General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
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
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