我有一个视图,它连接两个表并按第一个表排序。除了顺序不正确。它错过了一个偶然的记录,然后在最后,大多数记录按顺序存在,然后在最后,其余记录按顺序存在。所以它有记录,如
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
我的看法如下。在我加入之前我需要做订单吗?我究竟做错了什么?(我已经获得了这个视图,并且另一个数据库实例中完全相同的视图可以正常工作。)
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
(编辑)排序字段的类型是 [ID] [int] NOT NULL IDENTITY(1, 1),