Search code examples
ssisssis-2008

SSIS Variable Expression Unexpected Results


I am writing a utility on SSIS 2008 that will check what day of the week it is and get the date for next Friday. This is what I have for a conditional if the current day of week is Wednesday.

DATEPART("dw",GETDATE())==4?DATEADD("dd", (DATEDIFF("dd",GETDATE() , GETDATE()) / 7) * 7 + 9, GETDATE())

The DATEADD portion is working when I take the ? operator out. Am I missing something?

Here is the error I am receiving

Expression cannot be evaluated
Attempt to parse the expression failed. 
The expression might contain an invalid token, an incomplete token, or an invalid element. 
It might not be well-formed, or might be missing part of a required element such as a 
parenthesis.


Solution

  • Assuming we're talking about the SSIS Expression language here (given the double quotes, I think that's a safe assumption)

    The SSIS Expression language uses the ternary operator ? : but that's not what you're doing. You're mixing ? with ,

    DATEPART("dw",GETDATE())==4?DATEADD("dd", (DATEDIFF("dd",GETDATE() , GETDATE()) / 7) * 7 + 9, GETDATE()) : GETDATE()