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 |
|
im1dermike
Posting Yak Master
222 Posts |
Posted - 2010-01-11 : 15:09:33
|
| I have a table that contains files for different customers. The types of files can be "CDC", "WSC", and "WAR". Any number of those files can exist meaning there could only be a "CDC" record for an agency, "CDC" and "WAR", or all three. I would like the result of my query to be ordered in the same order above ("CDC", "WSC", and "WAR"). Is there a way to add a custom order in an ORDER BY condition to accomplish what I'd like or should I do it after I get the query back (in C#)?Thanks |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2010-01-11 : 15:10:50
|
| Yes. You can use a CASE statement in your ORDER BY clause. |
 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2010-01-11 : 15:15:07
|
Like..select * from <urtable>order by case file_type when 'CDC' then 0 when 'WSC' then 1 when 'WAR' then 2else 9 end |
 |
|
|
im1dermike
Posting Yak Master
222 Posts |
Posted - 2010-01-11 : 15:17:45
|
Seems obvious now, but I just wasn't thinking along those lines for whatever reason. Thanks so much vijay. |
 |
|
|
DP978
Constraint Violating Yak Guru
269 Posts |
Posted - 2010-01-11 : 15:19:47
|
| Vijay you are on fire today! |
 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2010-01-11 : 15:21:53
|
quote: Originally posted by im1dermike Seems obvious now, but I just wasn't thinking along those lines for whatever reason. Thanks so much vijay. 
Np. You're welcome. |
 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2010-01-11 : 15:22:30
|
quote: Originally posted by DP978 Vijay you are on fire today!
Yeah. Its that kind of day at work...Damn..I hate doing documentation. This is so much better |
 |
|
|
|
|
|