Problem with IF statement and deciding which portion of code to run

  • I've not gotten the If statement to work.

    Before: http://www.webfound.net/sqlbefore.txt

    After (with IF statement):

    http://www.webfound.net/sqlafter.txt

    I don't want to include the deletedpdcs if the month is today in my SUM for PDCs_IL basically is what I'm trying to accomplish here

  • The IF statement is a T-SQL control flow statement, and is not meant to be embedded within SQL statements. It looks like you're trying to build a different derived table, depending on the IF evaluation, which is not possible or legal T-SQL syntax. 

    Declare a table type variable.

    Use the IF to determine what to populate the table type variable with.

    Join the table type variable to your main query instead of the conditonal derived table.

     

     

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

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