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 |
|
JezLisle
Posting Yak Master
132 Posts |
Posted - 2009-10-19 : 09:57:50
|
| How is it possible to find the Max date across a number of fields?I have Appt1Appt2Appt3Appt4Appt5How can I find the max value for each record over these fields? |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-10-19 : 10:03:23
|
[code]select max(appt)from( select max(Appt1) as appt from sometable union all select max(Appt2) as appt from sometable union all select max(Appt3) as appt from sometable union all select max(Appt4) as appt from sometable union all select max(Appt5) as appt from sometable) a[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
JezLisle
Posting Yak Master
132 Posts |
Posted - 2009-10-19 : 10:09:50
|
| Thanks, but will that be for the whole table or will it work for each record? as I want to find this for each record in the table |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-10-19 : 10:12:41
|
that for whole table. For each record, you write a UDF to do thatand in the UDF, select max(appt)from( select @appt1 as appt union all select @appt2 as appt union all select @appt3 as appt union all select @appt4 as appt union all select @appt5 as appt ) a KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
JezLisle
Posting Yak Master
132 Posts |
Posted - 2009-10-19 : 10:15:29
|
| how do you mean UDF? |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-10-19 : 10:16:31
|
UDF = User Defined Function KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|
|