Link to home
Start Free TrialLog in
Avatar of VBdotnet2005
VBdotnet2005Flag for United States of America

asked on

Update and return 0 or 1

Is it possible if below update successfully, I want it to return 0, if not return 1.

create procedure Updatesample
@id            int
@username      varchar(12)
as

Update table1

set username = @username

where id =@id

IF @@ROWCOUNT = 0
BEGIN
   --  ???

result
0 or 1
Avatar of Aneesh
Aneesh
Flag of Canada image

create procedure Updatesample
@id            int
@username      varchar(12)
as
set nocount on
Update table1
set username = @username
where id =@id

IF @@rowcount > 0 retrun 1
else return 0

go

or

you can return the @@rowcount whcich is nothing but the no of rows affected by the last statement which in this case is the update statement
Avatar of VBdotnet2005

ASKER

It says "(1 row(s) affected)", How can I return result like below?

   columnname
   0

or columnname
    1
ASKER CERTIFIED SOLUTION
Avatar of Aneesh
Aneesh
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial