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.
| Author |
Topic |
|
kirank
Yak Posting Veteran
58 Posts |
Posted - 2011-05-14 : 14:38:56
|
| how to assign order by Declare @SortExp as varchar(50) if @mSortBy = 'New' begin set @SortExp = 'addon desc' end order by @SortExp if i run like this it gives me error as Incorrect syntax near the keyword 'order'. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2011-05-14 : 17:41:29
|
Untested, but I know the case in Order By does workORDER BY CASE WHEN @mSortBy = 'New' THEN addon ELSE SomeOtherColumn END DESC --Gail ShawSQL Server MVP |
 |
|
|
kirank
Yak Posting Veteran
58 Posts |
Posted - 2011-05-15 : 12:32:51
|
| thx for the help helpactually here desc is also not fix it may change asc alsosenario is CASE WHEN @mSortBy = 'New' THEN addedon DESC WHEN @mSortBy = 'Old' THEN Old ASc WHEN @mSortBy = 'Prev' THEN Prev Asc ELSE SomeOtherColumn END so plz help me here i cant specify this asc or desc |
 |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2011-05-15 : 12:38:02
|
| See Tara's reply in that case.--Gail ShawSQL Server MVP |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2011-05-15 : 23:29:53
|
You can use a dual order by case.order bycase when @msortby = 'new' then addedon else null end desc,case when @msortby = 'old' then old when @msortby = 'prev' then prev else null end asc N 56°04'39.26"E 12°55'05.63" |
 |
|
|
kirank
Yak Posting Veteran
58 Posts |
Posted - 2011-05-16 : 13:43:13
|
| thx for reply. here i have change like this way. case when @msortby = 'new' then addedon else null end desc, case when @msortby = 'descpop' then b.rating end desc, case when @msortby = 'descrating' then b.rating else null end aschttp://webdevlopementhelp.blogspot.com |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|
|
|