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 |
|
padsp
Starting Member
21 Posts |
Posted - 2005-09-19 : 13:24:33
|
| Hi,I'm using Sql Server 2000, don't know how to order result set.I have table called TAB1 has the following structure with sample data:Table TAB1:EMP_ID EST_ID MTG_ID DTUPD DTNH164 12 219 2003-01-18 1900-01-01164 12 340 2003-04-22 1900-01-01164 24 800 1900-01-01 2004-06-06164 24 807 2005-06-12 1900-01-01I would like to show the result set as follows:Table TAB1:EMP_ID EST_ID MTG_ID DTUPD DTNH164 24 807 2005-06-12 1900-01-01164 24 800 1900-01-01 2004-06-06164 12 340 2003-04-22 1900-01-01164 12 219 2003-01-18 1900-01-01Basically i would like to sort by latest date(DTUPD,DTNH).I'm looking for your help.I've tried query like this,But no luckSELECT * FROM TAB1 WHERE EMP_ID=164 ORDER BY DTUPD,DTNH descThanksBob |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-09-19 : 13:35:17
|
try changing ORDER BY DTUPD,DTNH descto ORDER BY DTUPD desc, DTNH descyou have to put desc to every column name in the order by list if you want to order them all in the descending way.Go with the flow & have fun! Else fight the flow |
 |
|
|
padsp
Starting Member
21 Posts |
Posted - 2005-09-19 : 13:50:35
|
| Hi spirit1,I have tried as you have suggested, this is what i'm getting,Table TAB1:EMP_ID EST_ID MTG_ID DTUPD DTNH164 24 807 2005-06-12 1900-01-01164 12 340 2003-04-22 1900-01-01164 12 219 2003-01-18 1900-01-01164 24 800 1900-01-01 2004-06-06The query i've used,SELECT * FROM TAB1 WHERE EMP_ID=164 ORDER BY DTUPD desc,DTNH descThe problem is here order works independently. but i would like order both cols together. |
 |
|
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2005-09-19 : 14:32:20
|
try:Order By (case when DTUPD > DTNH then DTUPD else DTNH end) descCorey Co-worker on The Wizard of Oz "...those three midgets that came out and danced, the freaked me out when I was little. But they are ok now." |
 |
|
|
|
|
|
|
|