As we all know, for sorting the values while fetching records we need to make use of ORDER BY clause.
That said, would the below code snippet work?
CREATE VIEW SampleView
AS
SELECT Sno, Firstname
FROM employeeTable
ORDER BY Firstname
GO
Nope it won't!!!
The work around is, we need to use "TOP 100 PERCENT" in our query if we want to use ORDER BY clause in a View (or) a Subquery (or) a derived table. (BTW this is possible in SQL Server 7.0 and SQL Server 2000).
See below the modified code snippet:
CREATE VIEW SampleView
AS
SELECT
TOP 100 PERCENT Sno,
Firstname
FROM
employeeTable
ORDER BY Firstname
That said, would the below code snippet work?
CREATE VIEW SampleView
AS
SELECT Sno, Firstname
FROM employeeTable
ORDER BY Firstname
GO
Nope it won't!!!
The work around is, we need to use "TOP 100 PERCENT" in our query if we want to use ORDER BY clause in a View (or) a Subquery (or) a derived table. (BTW this is possible in SQL Server 7.0 and SQL Server 2000).
See below the modified code snippet:
CREATE VIEW SampleView
AS
SELECT
TOP 100 PERCENT Sno,
Firstname
FROM
employeeTable
ORDER BY Firstname
Comments