Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Update and return 0 or 1

Posted on 2013-01-29
3
Medium Priority
?
259 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 2000 total points
ID: 38833327
instead of return use select

select 1 as columnName
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
I have a large data set and a SSIS package. How can I load this file in multi threading?
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.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

721 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