SQL Server Performance

How to set and check condition

Discussion in 'SQL Server 2005 Integration Services' started by BKolb, Jun 1, 2009.

  1. BKolb New Member

    I want to use an Execute SQL Task to check the count of records in a table. For instance:
    SELECT count(*) as tblCount from myTable
    I want to use the value of tblCount as a condition to set the success of this task as true or false. In other words, if tblCount is 0, then I want this task's result status to be set to FAILURE, but if it's > 0, I want it to be set to SUCCESS. Then, I can use this result to decide if I continue with the next task or not.
    Is it possible to set the result status of a task like this, and if so, how?
    Thank you so much for your help.
  2. sgovoni New Member

    Hi BKolb,
    you could use a statement if...else:
    if (SELECT count(*) as tblCount from myTable) = 0
    begin
    -- break
    end
    else begin
    -- continue
    end
    Bye

Share This Page