Link to home
Create AccountLog in
Avatar of pauldes
pauldes

asked on

Why would a select of an integer return a datetime value in a CASE statement?

Why doesn't this statement return 1? Instead it returns 1900-01-02 00:00:00.000. How would you format this to  return a 1 or 2 in the last 2 conditions and a proper datetime value in the other conditions of the CASE?

SELECT
CASE WHEN ''='Day' THEN '01/01/2001'
WHEN ''='Week' THEN DATEADD(d, 1 - DATEPART(dw, '01/01/2001'), '01/01/2001')  
WHEN ''='Month' THEN Month('01/01/2001') + Year('01/01/2001')
WHEN ''='Year' THEN Year('01/01/2001')
WHEN ''='Employee' THEN 2
ELSE 1 END as [grouping]
ASKER CERTIFIED SOLUTION
Avatar of Aneesh
Aneesh
Flag of Canada image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer