Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ORDER BY in stored procedures

Status
Not open for further replies.

gojohnnygogogogo

Programmer
Joined
May 22, 2002
Messages
161
Location
GB
hello,
I am trying to order by in my sp, but I can't.
I am doing this :

SELECT * FROM table
ORDER BY INSERTDATE DESC
UNION
SELECT * FROM table

and I get the erorr :
incorrect syntax near the keyword UNION.

anybody seen this before ?
 
Order by should come after all the union queries have been defined. It applies to the complete result set after union and not to individual result sets, hence the error. The code should be something like

SELECT * FROM table
UNION
SELECT * FROM table
ORDER BY INSERTDATE DESC
RT
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top