I have a view that is joining two tables and ordering by the first table. Except that the order isn't correct. It misses an occasional record, and then at the end, most of those records exist in order, and then at that end, the rest of the records exist in order. So it has records such as
1 (most of the records in order)
2
4
5
6
7
8
10
11
13
15
3 (the first set of missing records)
12
9 (the rest of the missing records)
14
My view is below. Do I need to do the order by before I do the join? What am I doing wrong? (I've acquired this view, and the exact same view in another db instance works correctly.)
CREATE VIEW [dbo].[SampleView]
AS
SELECT TOP 100 PERCENT blp.*, ISNULL(YEAR(DATEADD(month, 2, tb.[End of D&D])), 0) AS DEMO_FY
FROM dbo.Table1 AS blp LEFT OUTER JOIN
dbo.Table2 AS tb ON blp.FACIL_NAME = tb.[Structure ID]
ORDER BY blp.ID
(edit) The type for the sort field is [ID] [int] NOT NULL IDENTITY(1, 1),