Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Dynamic SQL and Variables
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Divers
Thread ID:
00235209
Message ID:
00236155
Vues:
21
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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform