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
VBdotnet2005Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Aneesh RetnakaranConnect With a Mentor Database AdministratorCommented:
instead of return use select

select 1 as columnName
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
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
0
 
VBdotnet2005Author Commented:
It says "(1 row(s) affected)", How can I return result like below?

   columnname
   0

or columnname
    1
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.