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 |
|
soorajtnpki
Posting Yak Master
231 Posts |
Posted - 2008-12-10 : 06:33:55
|
| hi all, see below query give errordeclare @SortOrder varchar(20)set @SortOrder='asc'select salesmanname,rate as Priority from salesorder by case when @SortOrder = 'first' then Priority end case when @SortOrder = 'asc' then salesmanname,Priority ASC end case when @SortOrder = 'desc' then customers.salesmanname DESC,Priority ASC end tanx in advance |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-12-10 : 06:39:18
|
Did you check Books Online first? The Microsoft SQL Server helpfile...select salesmanname, rate as Priority from salesorder by case @SortOrder when 'first' then rate when 'asc' then salesmanname else null end, case @SortOrder when 'desc' then salesmanname else null end DESC, Priority E 12°55'05.63"N 56°04'39.26" |
 |
|
|
soorajtnpki
Posting Yak Master
231 Posts |
Posted - 2008-12-10 : 06:59:40
|
| hi peso thanks |
 |
|
|
soorajtnpki
Posting Yak Master
231 Posts |
Posted - 2008-12-10 : 08:00:22
|
quote: Originally posted by Peso Did you check Books Online first? The Microsoft SQL Server helpfile...select salesmanname, rate as Priority from salesorder by case @SortOrder when 'first' then rate when 'asc' then salesmanname else null end, case @SortOrder when 'desc' then salesmanname else null end DESC, Priority E 12°55'05.63"N 56°04'39.26"
hi we can further reduce to the followingselect salesmanname, rate as Priority from salesorder by case @SortOrder when 'asc' then salesmanname else null end, case @SortOrder when 'desc' then salesmanname else null end DESC, Priorityam i right? |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-12-10 : 08:19:26
|
quote: Originally posted by soorajtnpki
quote: Originally posted by Peso Did you check Books Online first? The Microsoft SQL Server helpfile...select salesmanname, rate as Priority from salesorder by case @SortOrder when 'first' then rate when 'asc' then salesmanname else null end, case @SortOrder when 'desc' then salesmanname else null end DESC, Priority E 12°55'05.63"N 56°04'39.26"
hi we can further reduce to the followingselect salesmanname, rate as Priority from salesorder by case @SortOrder when 'asc' then salesmanname else null end, case @SortOrder when 'desc' then salesmanname else null end DESC, Priorityam i right?
YesMadhivananFailing to plan is Planning to fail |
 |
|
|
soorajtnpki
Posting Yak Master
231 Posts |
Posted - 2008-12-10 : 08:22:05
|
| HI VERY THANX MADHIVANAN |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-12-10 : 09:14:10
|
What happened to "first" case, to sort to RATE? E 12°55'05.63"N 56°04'39.26" |
 |
|
|
soorajtnpki
Posting Yak Master
231 Posts |
Posted - 2008-12-10 : 23:26:00
|
| hi peso we can avoid first case checking, as we got the same results for your query and the modified one. Am i right ?ok tanx peso |
 |
|
|
|
|
|
|
|