sql - Find between with separated date fields (year,month,day) -
i have following dates in table in separated fields. how can write query show values between 2 dates. example: values between 2/1/2011 , 2/6/2011:
day month year value -------------------------------------------------- 2 6 2011 120 3 7 2011 130 5 5 2011 100 6 1 2011 50
as others have said, first suggestion use date. or if need more detailed information example, datetime or timestamp time zone.
but in case have work data, think should work, depending on flavor of sql:
select value, convert(date,concat(concat(concat(concat(day, "-"), month), "-"), year), 105) date table_name (2/1/2011) <= date , date <= (2/6/2011);
(with oracle sql, can use to_date instead of convert , optionally use || concatenation operator; sql server have use + concatenation operator; mysql should right)
(2/1/2011) , (2/6/2011) either strings convert similar other convert, or inputted using preparedstatement or dates directly (this preferable).
Comments
Post a Comment