Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Help with TOP and UNION
Message
De
27/12/2004 13:58:06
John Deupree
Long Term Care Authority
Tulsa, Oklahoma, États-Unis
 
 
À
27/12/2004 12:41:59
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00972363
Message ID:
00972411
Vues:
12
Thanks for the reply. I had forgotten about using a sub-query as a table.

John

>>Yep, I was hoping to bypass the stored procedure route, but it looks as though it's the only way.
>>
>>Thanks
>>
>>>You can do the first select into a cursor and than add new record with Null date.
>>>
>>>>Oops, sorry. I know the problem of not being able to use the order by in the first select. Any ideas on how to return the correct results?
>>>>
>>>>John
>>>>
>>>>>You've to add 'order by begin_date desc' to the first select in whcih case it cannot be UNION.
>>>>>
>
>This return max 3 rows:
>
>SELECT*FROM (
>    SELECT TOP 2 plan , begindate FROM mytable ORDER BY begindate DESC) _
>UNION ALL
>    SELECT MAX(plan)+1, NULL      FROM mytable
>* ORDER BY .. . it is redundant
>
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform