As it states - you cannot include an ORDER BY
clause in the definition of a view. It is in much the same way that the order of data returned from a table when no ORDER BY is applied on the SELECT means that the order of data is not guaranteed.
Apply the ORDER BY
in the queries that SELECT from the view instead.
Instead of
ALTER VIEW [dbo].[vw_Test_booking]
AS
select NEWID() as UniqueKey, *
from (
SELECT [startdatetime] AS StartDateTime,
[bookingdatetime] AS BookingDateTime,
[firstname] AS firstname
FROM [dbo].[vw_Testpatient]
WHERE statusCode in (
'2',
'0
)
) T
ORDER BY startdatetime DESC
Apply it like
SELECT *
FROM dbo.vw_Test_booking
ORDER BY StartDateTime DESC
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…