Avatar of PHS_IT
PHS_IT
 asked on

CAN I USE DATEPART IN ( ) ?

What is wrong with this statement?  I know I must have a comma out of place, or a ( in the wrong place.  Or can I not use IN with DATEPART???

CASE WHEN TPR200_EMPLOYEE_MASTER.lst_rvw_dt IS NULL AND
DATEPART(m, TPR200_EMPLOYEE_MASTER.nxt_rvw_dt) IN ('5', '6', '7')) THEN 1
         ELSE 0 END AS CountDueQtr1
Microsoft SQL Server 2005Microsoft SQL Server

Avatar of undefined
Last Comment
PHS_IT

8/22/2022 - Mon
ptjcb

What is the error message?
PHS_IT

ASKER
Msg 170, Level 15, State 1, Line 67
Line 67: Incorrect syntax near ')'.
ASKER CERTIFIED SOLUTION
ptjcb

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ptjcb

without seeing the entire script - it may be the extra ) after the list. Try this one:


CASE WHEN TPR200_EMPLOYEE_MASTER.lst_rvw_dt IS NULL AND
DATEPART(m, TPR200_EMPLOYEE_MASTER.nxt_rvw_dt) IN ('5', '6', '7') THEN 1
         ELSE 0 END AS CountDueQtr1
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
CmdoProg2

You have an extra close parathensis
DATEPART(m, TPR200_EMPLOYEE_MASTER.nxt_rvw_dt) IN ('5', '6', '7') THEN 1
PHS_IT

ASKER
ptjcb,
Thanks, you caught it.  I stared at it too long.  CmdoProg2, you were right also, but I was already working with ptjcb, so I will award the points there.  Thanks for your assistance.