|
Hey there, quick question for you gurus: I have a very simple stored procedure that creates two tables, my requirement is to output the numbe of rows inserted into each table, I stumbled across @@ROWCOUNT and this has allowed me to return the value from the last table, or if I put that in between, execution stops immediately after - which is not good, this is my code: Any suggestions would be appreciated. Any suggestions would be appreciated, thanks! Sheep
(comments are locked)
|
|
Instead of using The problem with this approach is if you want to process both outputs within other T-SQL code. However, that doesn't seem to be concerning the @TelepathicSheep2, but I thought I should mention it anyway!
Nov 25 '11 at 12:56 PM
ThomasRushton ♦
Yes I was just going for the assumption that OP wants to see 'output', and the return was stopping the batch mid-way
Nov 25 '11 at 01:05 PM
Kev Riley ♦♦
He explicitly said it was for a stored procedure. I'm scratching my head wondering how you can access two results from a stored procedure in TSQL. I've never known of a general way. In this case you can insert them into one table (by insert EXEC) as they are the same and same no. of columns, but then you've got the problem of accessing them. No, horrible.
Nov 25 '11 at 01:55 PM
Phil Factor
Didn't even read that bit! As ever, what the OP wants, and what the OP says and what the OP likes are mutually exclusive.....
Nov 25 '11 at 02:11 PM
Kev Riley ♦♦
(comments are locked)
|
|
By far the most serviceable way to do this is to use two output variables to pass back the rowcounts. If you can't do that for some reason, then you can pass back the two rowcounts as columns in a single row table, but it is messy to pick up these values outside the stored procedure if you need to assign them to variables. I've never worked with output variables, if you were able to provide some sample code it'd be great (save me a lot of time). Otherwise, I'll google it and try my best - thanks for your help. Sheep
Nov 25 '11 at 10:09 AM
TelepathicSheep2
@TelepathicSheep2 - try here as a starting point: http://msdn.microsoft.com/en-us/library/ms378108(v=sql.90).aspx
Nov 25 '11 at 11:56 AM
ThomasRushton ♦
(comments are locked)
|

