SQLTeam.com | Weblogs | Forums

Using DATEADD in Case statement (MS Server 2012)

sql2012

#1

For certain security types, I'm attempting to create a column that adds one month to the ISSUE_DATE date and call it 'First Payment Date'. It works fine in the select statement when written as DATEADD(month,1,s.ISSUE_DATE) 'First Pay Date' but I'm not having any luck using it in a CASE statement. I'm getting an "Incorrect Syntax Error" on the ")"
Here is my SQL
Select s.CUSIP, s.ISSUE_DATE, DATEADD(month,1,s.ISSUE_DATE) 'First Pay Date',
(Case when s.SEC_TYP_CD = 'FNMA' Then DATEADD(MONTH,1,s.ISSUE_DATE) else s.issue_date) 'First Pay Date'
from CSM_SECURITY s
where CUSIP = '3136ACES6'

This case statment will be part of a broader existing export job which encompasses all security types, so I cannot just filter by the 'FNMA' sec type in the where clause. Any help would be appreciated.


#2

"Case" requires an "End", that's probably the only problem:

Select s.CUSIP, s.ISSUE_DATE, DATEADD(month,1,s.ISSUE_DATE) 'First Pay Date',
(Case when s.SEC_TYP_CD = 'FNMA' Then DATEADD(MONTH,1,s.ISSUE_DATE) else s.issue_date End) 'First Pay Date'
from CSM_SECURITY s
where CUSIP = '3136ACES6'


#3

Of course it does! Thank you.