Solved

Update and return 0 or 1

Posted on 2013-01-29
3
254 Views
Last Modified: 2013-01-29
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
Comment
Question by:VBdotnet2005
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 38833294
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
 

Author Comment

by:VBdotnet2005
ID: 38833317
It says "(1 row(s) affected)", How can I return result like below?

   columnname
   0

or columnname
    1
0
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 500 total points
ID: 38833327
instead of return use select

select 1 as columnName
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question