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
 General SQL Server Forums
 New to SQL Server Programming
 How to give case statement in Order By

Author  Topic 

aoriju
Posting Yak Master

156 Posts

Posted - 2011-09-27 : 03:33:16
DECLARE @str VARCHAR(100);

SET @str ='SR'

; with tbl as
(
select *, row_no = row_number() over (order by [RequestId])
from workflow_Request
)
select *
from tbl
where @str <> 'SR'
or (@str = 'SR' and row_no <= 10)


I want to use RequestId as Order By when it is not Null
else Order By as MasterId

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-09-27 : 03:36:42
[code]
ORDER BY isnull(RequestId, MasterId)
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

aoriju
Posting Yak Master

156 Posts

Posted - 2011-09-27 : 04:27:49
I have some other conditions..so looking for Case statement
Go to Top of Page

Ranjit.ileni
Posting Yak Master

183 Posts

Posted - 2011-09-27 : 04:33:47
some thing like this..


ORDER BY
CASE WHEN col1!='Transfer' THEN col2 END
,CASE WHEN col1='Transfer' THEN col3 END DESC







--Ranjit
Go to Top of Page
   

- Advertisement -