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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2002-03-01 : 08:48:14
|
| Simon writes "Love the CASE WHEN approach, very nifty once I got it working!Here's a thing - I would like to be able to sort by more than one field--Existing Code-- ....ORDER BY CASE WHEN @OrderBy = 1 THEN vw_Candidates.CandidateID WHEN @OrderBy = 3 THEN vw_Candidates.DOB WHEN @OrderBy = 6 THEN vw_Candidates.LastUpdated END ASC, CASE WHEN @OrderBy = 2 THEN vw_Candidates.Surname WHEN @OrderBy = 4 THEN vw_Candidates.myLocation WHEN @OrderBy = 5 THEN vw_Candidates.myCat WHEN @OrderBy = 7 THEN vw_Candidates.WhereIsCV END ASC--Existing Code--What I'd like to be able to do is when @OrderBy is 2, to ORDER BY vw_Candidates.Surname ASC, vw_Candidates.FirstName ASCAny ideas?Thanks!simonSQL Server 7.0Win NT 4.0" |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2002-03-01 : 11:08:02
|
| ....ORDER BYCASE WHEN @OrderBy = 1 THEN vw_Candidates.CandidateIDWHEN @OrderBy = 3 THEN vw_Candidates.DOBWHEN @OrderBy = 6 THEN vw_Candidates.LastUpdatedEND ASC,CASEWHEN @OrderBy = 2 THEN vw_Candidates.Surname WHEN @OrderBy = 4 THEN vw_Candidates.myLocationWHEN @OrderBy = 5 THEN vw_Candidates.myCatWHEN @OrderBy = 7 THEN vw_Candidates.WhereIsCVEND ASC,case WHEN @OrderBy = 2 THEN vw_Candidates.FirstNameEND ASC==========================================Cursors are useful if you don't know sql.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|