You could certainly use CASE
Here is a sample table with sample data
CREATE TABLE MyDatesTable(Date1 smallDatetime NULL, Date2 smallDatetime
NULL)
GO
INSERT MyDatesTable(Date1, Date2) VALUES(NULL,DATEADD(day,10,Getdate()))
INSERT MyDatesTable(Date1, Date2) VALUES(DATEADD(day,20,Getdate()),NULL)
INSERT MyDatesTable(Date1, Date2) VALUES(DATEADD(day,2,Getdate()),Getdate())
INSERT MyDatesTable(Date1, Date2) VALUES(Getdate(),DATEADD(day,4,Getdate()))
select
CASE WHEN Date1 IS NULL OR Date2 > Date1 THEN Date2
ELSE Date1
END as DateSelected
FROM
MyDatesTable
--
--
Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.SQLDTS.com - The site for all your DTS needs.
I support PASS - the definitive, global community
for SQL Server professionals -
http://www.sqlpass.org
"aaapaul" <lv****@gmx.net> wrote in message
news:36*************************@posting.google.co m...
I need the maxvalue of 2 colums for each row
Select date1, date2, maximum(date1,dat2) as datemax.
Is this simple to realize ?
date1 and date2 can be NULL.
something like this:
select date1,date2, maxdate =
CASE
when date1 is null then date2
when date2 is null then date1
else
if date1 > date2 then date1
else date2
from xy
thanks for your help
paul