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 |
|
vtxvtx
Starting Member
18 Posts |
Posted - 2012-09-04 : 07:21:43
|
| Hi,I've been trying to work out a min command (not for min in a column)what I want to do is as followsDatediff(mm,Date1,Min(Date2,Date3))Is there a command out there that can do that in sql?Thanks,Andy |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2012-09-04 : 07:35:19
|
datediff(mm,Date1,case when Date2 < Date3 then Date2 else Date3 end) Too old to Rock'n'Roll too young to die. |
 |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-09-04 : 07:37:54
|
There are no column-wise aggregate functions (MIN, MAX, AVG etc.) in T-SQL. You can make do with the following if you are looking for min between only two columns. If you have many columns that is in your aggregate, there are other ways, but none of them very pretty.Datediff(mm,Date1,Min(CASE WHEN Date2 < Date3 THEN Date2 ELSE Date3 END)) |
 |
|
|
vtxvtx
Starting Member
18 Posts |
Posted - 2012-09-04 : 07:48:14
|
| Thanks sunitabeck, There are 5 dates that I need to compare. I'll just write it as a case, was hoping not to do that, but oh well. Will just hope I dont need to add in any more dates to compare :). |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|
|
|
|