473,385 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Compare 2 DateValues -> maxvalue in transact sql

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
Jul 20 '05 #1
4 2567
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

Jul 20 '05 #2
Are you in Austria?

On 4 May 2004 02:38:43 -0700, lv****@gmx.net (aaapaul) wrote:
merci vielmals.

gruss
aaapaul


Jul 20 '05 #3
merci vielmals.

gruss
aaapaul
Jul 20 '05 #4
Are you in Austria?

On 4 May 2004 02:38:43 -0700, lv****@gmx.net (aaapaul) wrote:
merci vielmals.

gruss
aaapaul


Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: MrCoder | last post by:
Hey guys, my first post on here so I'll just say "Hello everbody!" Ok heres my question for you lot. Is there a faster way to compare 1 byte array to another? This is my current code //...
11
by: Russ Green | last post by:
How does this: public TimeSpan Timeout { get { return timeout; } set { timeout = value; if(timeout < licenseTimeout) licenseTimeout = timeout; }
10
by: Russ Green | last post by:
How does this: public TimeSpan Timeout { get { return timeout; } set { timeout = value; if(timeout < licenseTimeout) licenseTimeout = timeout; }
26
by: neha_chhatre | last post by:
can anybody tell me how to compare two float values say for example t and check are two variables declared float how to compare t and check please help me as soon as possible
1
by: Lambda | last post by:
I defined a class: class inverted_index { private: std::map<std::string, std::vector<size_t index; public: std::vector<size_tintersect(const std::vector<std::string>&); };
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.