[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 269
  • Last Modified:

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
0
VBdotnet2005
Asked:
VBdotnet2005
  • 2
1 Solution
 
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
 
Aneesh RetnakaranDatabase AdministratorCommented:
instead of return use select

select 1 as columnName
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now