OK,
SO, I want to get BOTH the any error codes that might have been thrown AND
if the statement is successful, how many records were updated.
Sounds like a simple request but it seems like I can only get one or the
other.
Example
DECLARE @ERRCODE
DECLARE @NUM_ROWS
UPDATE sometable SET field=x
SET @ERRCODE = @@ERROR
SET @NUM_ROWS = @@ROWCOUNT
With the aobe @NUM_ROWS is always 0 (I assume because the Set @ERRCODE =
@@ERROR statement didn't return or update any records)
UPDATE sometable SET field=x
SET @NUM_ROWS = @@ROWCOUNT
SET @ERRCODE = @@ERROR
With the aobe @ERRCODE is always 0 (I assume because the SET @NUM_ROWS =
@@ROWCOUNT statement didn't generate any errors)
So what's a guy to do !?!?!
Is it simply not possible to get both?
Regards,
Tom Malia
Plamen Ratchev - 25 Jul 2008 22:44 GMT
Use one statement:
SELECT @NUM_ROWS = @@ROWCOUNT, @ERRCODE = @@ERROR;
HTH,
Plamen Ratchev
http://www.SQLStudio.com
Thomas Malia - 25 Jul 2008 22:57 GMT
Ya know... I thought of that... but I figured that was like putting tons of
code in the
for() function in C... when I first started programming I thought "oh this
has GOT to be faster because it's 'just one line of code'" I was young and
stupid back then and didn't realized that that "one line" in my editor was
going to expand out to the same darn machine code code that 10 lines would
have...
I just assumed SQL would work the same. That's what you get for ASS-U-ME
ing
Thanks
> Use one statement:
>
[quoted text clipped - 4 lines]
> Plamen Ratchev
> http://www.SQLStudio.com
Plamen@sqlstudio.com - 25 Jul 2008 22:49 GMT
Use one statement:
SELECT @NUM_ROWS = @@ROWCOUNT, @ERRCODE = @@ERROR;
HTH,
Plamen Ratchev
http://www.SQLStudio.com