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 |
sql999
Starting Member
8 Posts |
Posted - 2012-10-23 : 23:38:47
|
here is the questionstart-date end-date2008-01-01 2008-11-212000-04-30 2001-10-102009-01-09 2009-10-19.....how to write the query to get the maximum date difference of the listThanks |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-10-24 : 01:57:18
|
[code]SELECT TOP 1 WITH TIES *FROM tableORDER BY DATEDIFF(dd,Start_date,End_date) DESC[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
sql999
Starting Member
8 Posts |
Posted - 2012-10-24 : 19:49:57
|
I tried it works, seems order by asc/desc + top can replace max(), min()thank you. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-10-25 : 00:00:47
|
quote: Originally posted by sql999 I tried it works, seems order by asc/desc + top can replace max(), min()thank you.
Not always. it depends on scenarioin cases you want max,min out of group you cant implement them using top and order by unless you use a subquery------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
sql999
Starting Member
8 Posts |
Posted - 2012-11-16 : 00:58:27
|
thank for your help |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-11-16 : 22:24:31
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|