How to cope with null results in SQL Tasks that return single rows in SSIS 2005?

Posted by JSacksteder on Stack Overflow See other posts from Stack Overflow or by JSacksteder
Published on 2010-05-28T17:53:54Z Indexed on 2010/05/30 17:52 UTC
Read the original article Hit count: 272

Filed under:
|

In a dataflow task, I can slip a rowcount into the processing flow and place the count into a variable. I can later use that variable to conditionally perform some other work if the rowcount was > 0. This works well for me, but I have no corresponding strategy for sql tasks expected to return a single row. In that event, I'm returning those values into variables. If the lookup produces no rows, the sql task fails when assigning values into those variables. I can branch on that component failing, but there's a side effect of that - if I'm running the job as a SQL server agent job step, the step returns DTSER_FAILURE, causing the step to fail. I can tell the sql agent to disregard the step failure, but then I won't know if I have a legitimate error in that step. This seems harder than it should be.

The only strategy I can think of is to run the same query with a count(*) aggregate and test if that returns a number > 0 and if so running the query again without the count. That's ugly because I have the same query in two places that I need to keep in sync.

Is there a better way?

© Stack Overflow or respective owner

Related posts about sql-server-2005

Related posts about ssis