rayh 98086 (7/11/2013)
Hello,I would like to create a SQL query that will make a decision based on date. For example, if the date is Jun 30,2013 or greater, then show 2013, else 2012.
IF myDate>6/30/2013 THEN '2013' ELSE '2012' as getSeason FROM myTable
I know this is not the write syntax, but is it possible to do something this way?
the CASE statement is used in sQL to do that; but in your case, you might want to use the YEAR function for this specific issue;
so it would look something like this:
SELECT
OtherColumns,
CASE
WHEN myDate > '6/30/2013'
THEN '2013'
ELSE '2012'
END as getSeason
FROM myTable
--or
SELECT
OtherColumns,
YEAR(myDate) AS getSeason
FROM myTable
Lowell