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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Selecting Min Date From 3 Columns in 1 Row

Author  Topic 

d473566
Starting Member

23 Posts

Posted - 2005-11-13 : 22:39:10
I have a query that returns a recordset such as:

ID | FromDate1 | FromDate2 | FromDate3
22 | 01/01/2003 | 01/01/2002 | 01/01/2004 |
23 | 01/01/1997 | 01/01/1991 | 01/01/1992 |
24 | 01/01/1984 | 01/01/1981 | 01/01/1982 |
25 | 01/01/1974 | 01/01/1976 | 01/01/1972 |


I need to add another column to my recordset that will hold the minumum date from the 3 columns in each row. The result would look something like:

ID | FromDate1 | FromDate2 | FromDate3 | MinDate
22 | 01/01/2003 | 01/01/2002 | 01/01/2004 | 01/01/2002
23 | 01/01/1997 | 01/01/1991 | 01/01/1992 | 01/01/1991
24 | 01/01/1984 | 01/01/1981 | 01/01/1982 | 01/01/1981
25 | 01/01/1974 | 01/01/1976 | 01/01/1972 | 01/01/1972

Thanks to all for any direction....

Derek

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2005-11-13 : 23:37:15
Somthing like this ..

Select ID,FromDate1,FromDate2,Fromdate3,Case When FromDate1>FromDate2 And FromDate1 > FromDate3 Then FromDate1
When FromDate2>FromDate1 And FromDate2>FromDate3 Then FromDate2
Else
FromDate3
End
From <TableName>

Complicated things can be done by simple thinking
Go to Top of Page
   

- Advertisement -