Case Statement in SSIS

  • I have a Execute SQL Task and calculate the DateTime for Start-Date & End-Date. Then based on a variable that is passed to the Task, the applicable INSERT statement is executed.

    The code below doesn't work It gives me the error "Incorrect syntax near the keyword 'CASE'.

    Sorry, I guess I have either the syntax wrong or the CASE statement doesn't work in SSIS.

    Please help.

    DECLARE @StartDate varchar(20)

    DECLARE @EndDate varchar(20)

    SET @NewStatusCd = 'S'

    SET @StartDate = (select (CONVERT(CHAR(9),GETDATE(),1) + SUBSTRING(CONVERT(CHAR(5),GETDATE(),14),1,5) + ' ' ))

    SET @EndDate = (select (CONVERT(CHAR(9),GETDATE(),1) + SUBSTRING(CONVERT(CHAR(5),GETDATE(),14),1,5) + ' ' ))

    CASE WHEN @NewStatusCd = S THEN INSERT INTO MyTable values (@NewFileName,@NewFileType,@StartDate,NULL,@NewStatusCd)

    WHEN @NewStatusCd = C THEN INSERT INTO MyTable values (@NewFileName,@NewFileType,NULL,@EndDate,@NewStatusCd)

    END

  • For this code, use IF...ELSE

    Converting oxygen into carbon dioxide, since 1955.
  • Steve, you are awesome. I guess I'm making this too hard. 😀

    thanks again!

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply