I am trying to create a query which populates the salesPeriod
field from the salesDate
field. The query should return a string value
based on the date part of the salesDate
. The conditions are:
If month is equal to equal to 11, 12, 1, return "Christmas Sales"
If month is equal to 6,7,8 return "Summer sales".
Otherwise return return "N/A"
Perhaps something like:
salesPeriod: DatePart("month",[salesDate])) = 11 Or 12 Or 1)....
or any direction?
Advertisement
Answer
You can use the month()
function and conditional logic. Here is one method:
select iif(month(salesDate) in (11, 12, 1), "Christmas Sales", iif(month(salesDate) in (6, 7, 8), "Summer sales", "N/A") ) as salesPeriod