473,386 Members | 1,763 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Value of @@Error after performing update that finds no records?

Hi All,

Just wondering if you perform an update using a where condition that
actually returns no rows to be updated, does @@Error contain an error
message afterwords?

We want to fire an update ona table against records that may or may
not exists. As a matter of course we test for an @@Error afterwards
and rollback our transaction and exit our stored proc if an error is
returned.

However, we don't want this to happen if there are no records in the
target table that match the where clause of the update statement.

So, if no records are found, does this raise an error?

Many thanks in advance!

Much warmth,

Murrau
Jul 20 '05 #1
2 2117
Hi

Just because no rows are updated does not mean it is an error!! @@ERROR will
still be 0
The number of rows changed will be in @@ROWCOUNT. This could have been
ascertained with a simple test such as:

create table Myupdatetable ( id int, val char(1) )

insert into Myupdatetable ( id, val ) values ( 1, 'A' )
insert into Myupdatetable ( id, val ) values ( 2, 'B' )
insert into Myupdatetable ( id, val ) values ( 3, 'C' )
UPDATE Myupdatetable
SET id = id + 2
WHERE ID % 2 = 1

SELECT @@ERROR, @@ROWCOUNT

UPDATE Myupdatetable
SET id = id + 2
WHERE ID = 0

SELECT @@ERROR, @@ROWCOUNT

John

"M Wells" <pl**********@planetthoughtful.org> wrote in message
news:8j********************************@4ax.com...
Hi All,

Just wondering if you perform an update using a where condition that
actually returns no rows to be updated, does @@Error contain an error
message afterwords?

We want to fire an update ona table against records that may or may
not exists. As a matter of course we test for an @@Error afterwards
and rollback our transaction and exit our stored proc if an error is
returned.

However, we don't want this to happen if there are no records in the
target table that match the where clause of the update statement.

So, if no records are found, does this raise an error?

Many thanks in advance!

Much warmth,

Murrau

Jul 20 '05 #2
On Thu, 01 Apr 2004 23:45:42 GMT, "John Bell"
<jb************@hotmail.com> wrote:
Hi

Just because no rows are updated does not mean it is an error!! @@ERROR will
still be 0
The number of rows changed will be in @@ROWCOUNT. This could have been
ascertained with a simple test such as:


Thank you John!

Much warmth,

Murray
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Robert Mark Bram | last post by:
Hi All! I have the following two methods in an asp/jscript page - my problem is that without the update statement there is no error, but with the update statement I get the following error: ...
4
by: Mark S. | last post by:
Hi, I have a weird UPDATE sequence I want to perform. The customer does not want to use INSERT and DELETE. My issue is that there are multiple Mat_Class, but I do not wish to hard code each one...
2
by: sean | last post by:
Hi, I am trying to update an access database using an SQL statement, I keep getting an syntax error in update statment. I am passing in strChkBoxValue as a string value which is declared in...
1
by: Kenneth | last post by:
Dear all, How can I update multiple records in using ASP.NET? Currently I have a table which require to update frequently but I can update records one by one using DataGrid. Kenneth
0
by: rhepsi | last post by:
Dear All, Im vb.net 1.1, When im trying to update the records from mysql to postgresql, the connection error: the following code is Update data button click: Dim myPgrConnect As...
1
by: hilal84 | last post by:
Hi, I have a problem on updating some records on sql server 2005. I can update the records in the table apart from some records. Records are added to table by a .net application. When I try to...
1
by: RP | last post by:
On my Windows Form, I have ten text boxes. I also have a DataGridView. When a user clicks a row on the DataGridView, the column values get displayed on their respective text boxes and are available...
1
Fary4u
by: Fary4u | last post by:
how can i update multiple records corresponding to perticular ID & update values in one go ? mode_a contains ID No. Dim mode,mode_a,i mode=Request("t1") mode_a=split(mode,",")
1
by: engrlorie | last post by:
I have four tables in access 2003: T1 (8 fields), t2 (5 fields), t3 (7 fields), t4 (3 fields) all connected to each other with t1.a = t2.a, t1.a=t3.a, t1.a=t4.a (T2, T3 and T4 contains the FK for T1....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.