compare date split across colums
- by alex-tech
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.