Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / Programming / SQL / July 2008

Tip: Looking for answers? Try searching our database.

@@ROWCOUNT and @@ERR !?!?!

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Thomas Malia - 25 Jul 2008 22:39 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.