Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Other SQL Server Topics (2005)
 Selecting a default always and return the other re

Author  Topic 

shakthiA
Starting Member

12 Posts

Posted - 2009-02-25 : 06:50:30
Hi

I have a stored procedure that returns all the docs uploaded ordered by creation date. Now i want to change it like show a document with the id "1234" as always on top and the remaining results as today after to that document.

For example:
Today we have stored procedure that returns the result as:

Id Title CreationDate Lang
1pqr About obama 24/02/2009 en
xyz You and Me 10/01/2009
abc KnowHow 01/12/2008 de
12345 Yes And No 29/10/2008 de

Now I want the result like:
Id Title CreationDate Lang
xyz You and Me 10/01/2009
1pqr About obama 24/02/2009 en
abc KnowHow 01/12/2008 de
12345 Yes And No 29/10/2008 de

Does anyone have any one idea.

Any Help please......!

Thanks in advance

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-02-25 : 08:43:52
How come there are 5 records in the wanted result, but only 4 in the provided sample data?



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-02-25 : 08:44:54
ORDER BY CASE WHEN ID = 'xyz' THEN 0 ELSE 1 END, CreationDate DESC



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

shakthiA
Starting Member

12 Posts

Posted - 2009-02-25 : 08:50:43
Hi Peso,

thanks for the reply. It worked. but can you explain it a little bit.

Thanks alot!!

quote:
Originally posted by Peso

ORDER BY CASE WHEN ID = 'xyz' THEN 0 ELSE 1 END, CreationDate DESC



E 12°55'05.63"
N 56°04'39.26"




Go to Top of Page
   

- Advertisement -