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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 search for value if exists?

Author  Topic 

chriskhan2000
Aged Yak Warrior

544 Posts

Posted - 2005-03-21 : 12:48:51
Can someone help me with this stored procedure. I'm trying to search to see if the value that the user entered exists or not. If not then in my asp.net page it will display msg, but if it do exists, then redirect them to the page detail section. Here's what I have but I don't think it's right.

CREATE PROCEDURE CW_QUOTESEARCH
@QUOTESEARCHID VARCHAR(10) = '',
@QUOTESEARCH int OUTPUT
AS
BEGIN
SET @QUOTESEARCH = IsNull((select id from quote where id = @QUOTESEARCHID),0)
END

Please advise. Thanks.

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-03-21 : 13:48:09
if exists(select id from quote where id = @QUOTESEARCHID)
set @QUOTESEARCH = 1
else
set @QUOTESEARCH = 0

Go with the flow & have fun! Else fight the flow
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-03-21 : 13:55:09
And don't forget to use SELECT * with IF EXISTS and IF NOT EXISTS for performance reasons. It's the only time to use SELECT *.

if exists(select * from quote where id = @QUOTESEARCHID)
set @QUOTESEARCH = 1
else
set @QUOTESEARCH = 0


Tara
Go to Top of Page

chriskhan2000
Aged Yak Warrior

544 Posts

Posted - 2005-03-22 : 10:46:40
Thanks both. GOt it now.
Go to Top of Page
   

- Advertisement -