compare date split across colums
Posted
by
alex-tech
on Stack Overflow
See other posts from Stack Overflow
or by alex-tech
Published on 2010-12-30T22:43:30Z
Indexed on
2010/12/30
22:54 UTC
Read the original article
Hit count: 142
sql
|sql-server
Greetings.
I am querying tables from Microsoft SQL 2008 which have date split across 3 columns: day, month and year. Unfortunately, I do not have control over this because data is coming in to the database daily from a 3rd party source in that format.
I need to add between to a where clause so user can pull records within a range. Would be easy enough if date was in a single column but finding it nearly impossible when its split across three columns.
To display the date, I am doing a
CAST(
CAST(year as varchar(4)) + '-' +
CAST(month as varchar(2)) + '-' +
CAST(day as varchar(2))
as date) AS "date"`
in a select. I tried to put it as a parameter for datediff function or just the regular between but get no results.
Thanks for any help.
© Stack Overflow or respective owner