Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Dynamic SQL and Variables
Message
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Miscellaneous
Thread ID:
00235209
Message ID:
00236374
Views:
15
>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
Map
View

Click here to load this message in the networking platform