Re: Error msg
- From: Erland Sommarskog <esquel@xxxxxxxxxxxxx>
- Date: Sun, 13 Nov 2005 10:30:36 +0000 (UTC)
Roy (Roy@xxxxxxxxxxxxxxxxxxxxxxxxx) writes:
> The stored procedures looks like this:
> CREATE PROCEDURE sp
> @ID int, @Parameter ...
> AS
> SET NOCOUNT ON
> SELECT * FROM table
> WHERE ID = @ID
> IF (@@ROWCOUNT <> 0)
> BEGIN
> // update record table here
> END
> ELSE
> BEGIN
> // add record to table here
> END
> RETURN @@ERROR
> GO
>
> These parameters are used to add/update records. Will they generate
> unconsumed result sets as you said?
"SELECT * FROM table" generates a result set which you need to process.
But if all you want to do is to check for existence, you should do:
IF NOT EXISTS (SELECT * FROM tbl WHERE id = @id)
BEGIN
INSERT ....
END
ELSE
UPDATE ...
END
--
Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
.
- Follow-Ups:
- Re: Error msg
- From: Roy
- Re: Error msg
- References:
- Re: Error msg
- From: Erland Sommarskog
- Re: Error msg
- From: Erland Sommarskog
- Re: Error msg
- Prev by Date: Re: Apartment model OLEDB Provider
- Next by Date: Samplclnt example in MDAC 2.8: My Story
- Previous by thread: Re: Error msg
- Next by thread: Re: Error msg
- Index(es):
Relevant Pages
|