General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
>Don,
>
>I was thinking about this in class today (I'm teaching SQL Admin this week) and I think that I have a pretty good solution. Try this:
>
>(Using the Northwind sample database)
>
>SELECT productname FROM
>(SELECT TOP 5 productname
> FROM products
> WHERE productname < 'konbu'
> ORDER BY productname DESC) AS a
>UNION
>SELECT productname FROM
>(SELECT TOP 6 productname
> FROM products
> WHERE productname >= 'konbu'
> ORDER BY productname ) AS b
>ORDER BY productname
>
>I'm using the SELECT TOP clause to limit the number of rows selected. The funny syntax is because a union can only have one ORDER BY clause. Since TOP has to have an ORDER BY, I have to use SQL Server's derived table feature.
>
>-Mike
I tried running the statment with respective table/field references and came up with error: Incorrect syntax near 5, and Incorrect syntax near 6 (with respect to the TOP keyword.) I searched documentation, and it doesn't appear that SQL 6.5 supports the TOP command. Is this sample based on SQL7?
Previous
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only