Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
evanburen
Posting Yak Master
167 Posts |
Posted - 2006-05-04 : 12:47:36
|
| Hi - I would like my @AddSubscriber output parameter to return the value 2 if the SELECT COUNT(Email) statement finds an existing email address. So something like this:IF (SELECT COUNT(Email) > 0 'return 2record successfully added 'return 1anything else 'return 0Thanks.*******************************************CREATE Procedure sp_AddSubscriber@Email as varchar(50), @AddSubscriber Int OUTPUTAS IF (SELECT COUNT(Email) FROM TSubscribers WHERE Email = @Email) = 0 BEGIN INSERT TSubscribers(Email) Values (@Email) SET @AddSubscriber = 1 END ELSE SET @AddSubscriber = 0GO |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2006-05-04 : 13:02:03
|
| And the question is? Are you asking how to retrieve the output value?declare @out intexec sp_AddSubscriber 'myEmail@myDomain.com', @out outputselect @outYou can also use a RETURN code for this type of thing.see RETURN in Books OnlineEDIT:btw, its not a good idea to name your procedures with "sp_" prefix. That is reserved for system stored procedures. You will take a (slight) performance hit because sql server will first look in the master database for this SP if you don't fully qualify the name.And since that particular SP already exists in Master you probably be envoking the wrong SP.Be One with the OptimizerTG |
 |
|
|
|
|
|