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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 What is wrong with this SQL code ?

Author  Topic 

paradise_wolf
Starting Member

32 Posts

Posted - 2007-02-05 : 06:53:11
CREATE PROCEDURE VerifyIfInvoiceExists
(@Invoice VARCHAR(50))
AS
DECLARE @DoesExist BIT
IF EXISTS (SELECT NULL FROM IPN_received
WHERE Invoice = @Invoice)
SELECT @DoesExist = 1
ELSE SELECT @DoesExist = 0
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I am getting an exception error. Any clue ?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-02-05 : 07:00:50
what is the error message ?

This is what you want ?

CREATE PROCEDURE VerifyIfInvoiceExists
(
@Invoice VARCHAR(50),
@DoesExist BIT OUTPUT
)
AS
IF EXISTS (SELECT NULL FROM IPN_received WHERE Invoice = @Invoice) SELECT @DoesExist = 1
ELSE SELECT @DoesExist = 0



KH

Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-02-05 : 07:03:38
"IF EXISTS (SELECT NULL FROM IPN_received ..."

Nothing to do with raising an error, but the convention is to use:

IF EXISTS (SELECT * FROM IPN_received ...

which is intended to allow SQL Server to choose which column / index / etc. it uses to satisfy the query.

Kristen
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2007-02-05 : 08:27:45
Duplicate thread
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=78539



CODO ERGO SUM
Go to Top of Page
   

- Advertisement -