Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

date compare in SQL

Status
Not open for further replies.

naushi

ISP
Jan 18, 2002
89
US
There are two dates date1 and date2 that need to be compared in a SQL. If date1 is greater than date2 I would select date1 and compare it in my where clause to be between start-dt and end-dt. If date2 is > than date1 then I would select date2 and compare it to be between start-dt and end-dt in a where clause.

this is how it would go

select <greater of date1 and date2> from .... where <greater of date1 and date2> between (start-dt and end-dt)

I know we can do a if date1 > then ..select and compare date1....
else select date2 and compare date2.

A better way to do it using a function that would return the greater of the two dates.

Can any one help with the function?


Regards,
Naushi Hussain
 
select greatest(date1,date2) from .... where greatest(date1,date2) between (start-dt and end-dt)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top