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:
00236155
Views:
20
I'll give it a try when I get back in the office tomorrow...

>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
Previous
Reply
Map
View

Click here to load this message in the networking platform