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 |
|
Mr Butter
Starting Member
3 Posts |
Posted - 2012-07-07 : 14:53:30
|
| Using Tsql I am looking to return the records where date1 is greater than date2 unless date2 is greater than any date1 entry. Table CaseNumber date1 date2123 12/25/2011 12/30/2011123 12/31/2011 456 12/25/2011 12/30/2011456 12/29/2011 Results CaseNumber date1 date2123 12/31/2011 456 12/25/2011 12/30/2011 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-07-07 : 16:29:53
|
| [code]SELECT CaseNumber,date1,date2FROM(SELECT ROW_NUMBER() OVER PARTITION BY CaseNumber ORDER BY COALESCE(date2,date1) DESC) AS Seq,*FROM Table)tWHERE Seq=1[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|