littlejon3


I am building this as an expression, but it is not working. I am trying to return the row count into a variable to use later in an update statement. What am I doing wrong I am using a single row result set. I have one variable defined in my result set. I am receiving an error stating: Execute SQL Task: There is an invalid number of result bindings returned for the ResultSetType: "ResultSetType_SingleRow". Any help is appreciated!

SELECT count(*) FROM hsi.itemdata a
JOIN hsi.keyitem105 b on a.itemnum = b.itemnum
JOIN hsi.keyitem106 c on a.itemnum = c.itemnum
JOIN hsi.keyitem108 d on a.itemnum = d.itemnum
WHERE a.itemtypegroupnum = 102
AND a.itemtypenum = 108
AND b.keyvaluechar = " + (DT_WSTR,2)@[User::Branch] + "
AND c.keyvaluechar = " + (DT_WSTR,2)@[User:Big Smileepartment] + "
AND d.keyvaluesmall = " + (DT_WSTR,7)@[User::InvoiceNumber] + ")




Re: Trying to set output variable to row count result of SQL Execute Task

BobP - BIM


Try naming your output (Select count(*) as recordCount...)

BobP







Re: Trying to set output variable to row count result of SQL Execute Task

DarrenSQLIS

Try adding an alias to the result column.

SELECT count(*) AS ItemCount FROM hsi.itemdata a

(The fact that it is an expression should have no impact. For testing I would stop using an expression and get it working with a static SQL statement, it often helps to simplify a problem process.)







Re: Trying to set output variable to row count result of SQL Execute Task

littlejon3

I have gone back to using static SQL statement and have added an alias, but the correct count is still not getting into my OUTPUT variable or RESULT SET variable so that it can be used later.

SELECT count(*) AS hcCount FROM hsi.itemdata a
JOIN hsi.keyitem105 b on a.itemnum = b.itemnum
JOIN hsi.keyitem106 c on a.itemnum = c.itemnum
JOIN hsi.keyitem108 d on a.itemnum = d.itemnum
WHERE a.itemtypegroupnum = 102
AND a.itemtypenum = 108
AND b.keyvaluechar =
AND c.keyvaluechar =
AND d.keyvaluesmall =





Re: Trying to set output variable to row count result of SQL Execute Task

jwelch

Make sure you are setting the result name to 0 in the Result Set page, where you map it to the variable.






Re: Trying to set output variable to row count result of SQL Execute Task

littlejon3

I am doing that.





Re: Trying to set output variable to row count result of SQL Execute Task

KOLDITZ

Instead of using a variable, another option could be to save your Select statement as a View in your database, and then use an SQL Task to Join it in a query when you need it.