• 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?

    Do you mean the current date? In other words if you run the query before June 30th it will show the previous year data but if you run the query after June 30th it will show the current year data? A little bit more detail is required here to provide an accurate answer.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/