473,512 Members | 15,196 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

printing messages with a Stored Procedure

2 New Member
Here is my SP:

Create PROCEDURE [dbo].[update_email]
(
@customerid as numeric(10),
@oldemail as varchar(50),
@newemail as varchar(50)
)
AS
BEGIN
update customerinfo
set email = @newemail
where @oldemail in (select email from customerinfo
where email = @oldemail)
and @customerid in (select customerid from customerinfo
where customerid = @customerid)
print 'Your email address has been updated'
end
begin
if @oldemail not in (select email from customerinfo
where email = @oldemail)
print 'Email not found'

END

My question is when I run this SP I receive both messages. I only want to receive one message. How do I make this work correctly, please help.
Dec 16 '06 #1
2 32402
almaz
168 Recognized Expert New Member
It looks like your query can be optimized.
Use this one:
Expand|Select|Wrap|Line Numbers
  1. Create PROCEDURE [dbo].[update_email]
  2. (
  3. @customerid as numeric(10),
  4. @oldemail as varchar(50),
  5. @newemail as varchar(50)
  6. )
  7. AS
  8. BEGIN
  9.     update customerinfo
  10.     set email = @newemail
  11.     where customerid = @customerid and email = @oldemail 
  12.  
  13.     IF @@ROWCOUNT<>0
  14.         print 'Your email address has been updated'
  15.     ELSE
  16.         print 'Email not found'
  17. END
Dec 18 '06 #2
triciameza
2 New Member
This works great, thank you very much.
Dec 18 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
3114
by: Dimitris | last post by:
I'm using ADO.NET to call a stored procedure that runs the "BACKUP" command on selected databases. Is there any way I can capture the text output of the stored proc and return it to ADO.NET for...
2
3385
by: Daniel | last post by:
hi ng, i am newbie to sqlserver and my problem seems simple, but i didn't find information about it: How can i display the RETURN @x value of a stored procedure in the sql analyzer of the...
5
6036
by: Lili | last post by:
I'm having problems creating a simple stored procedure in DB2. Can someone help? Here is the screen dump when I tried to load the stored procedure. Thanks for any help. Create procedure...
1
7317
by: Private Pyle | last post by:
DB2 version 8, fixpack 5. Aix 5.1.0.0 Using C for AIX compiler. I'm having a problem where I can create stored procedures but I'm getting -444 when I call them. It's a new environment for...
5
4282
by: dharmadam | last post by:
I am trying to build a simple SQL stored procedure in DB2 Stored Procedure Builder V7. It gives me the following message. Can someone help me to identify the problem. ...
1
9696
by: Raquel | last post by:
This is a stored procedure that resides on Mainframe and gets executed on the client by connecting to the mainframe through DB2 connect. It was executing fine till yesterday when I executed a table...
2
22837
by: Bill_DBA | last post by:
I have the following stored procedure that is called from the source of a transformation in a DTS package. The first parameter turns on PRINT debug messages. The second, when equals 1, turns on the...
1
2420
by: sshankar | last post by:
Hi, New to Stored procedure. Basically just installed DB2 v8.1.0.36 Was trying to build a stored procedure.. It is giving following error.. Looks like some error related to configuration...
0
3154
by: SOI_0152 | last post by:
Hi all! Happy New Year 2008. Il hope it will bring you love and happyness I'm new on this forum. I wrote a stored procedure on mainframe using DB2 7.1.1 and IBM language c. Everything works...
12
5116
by: Dooza | last post by:
I have a stored procedure that takes a number of inputs, does a bulk insert, and then outputs a recordset. When I run the stored procedure in Server Management Studio I also get a return value from...
0
7153
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7371
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7093
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7517
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5077
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
452
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.