Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can I search and insert if not found in one sp?
Message
General information
Forum:
Microsoft SQL Server
Category:
Other
Miscellaneous
Thread ID:
00846097
Message ID:
00846103
Views:
19
Hi Kirk,

You should be able to do this.

Have your SP return 0 if the record already exists, or the identity of the newly inserted record.

AL

>I'm rewriting some code and trying to move a method of code into a stored procedure. Currently, in my code:
>
>1. Check to see if item exists in table, using a stored procedure. (Select LocationID from coLocatins where locationCode=?lcLocationCode)
>2. If reccount()=0, then build code to insert record and run code to get the ID automaticly assigned @@Identity
>
>
>I'd like to be able to write one stored procedure that ran the select, if the result set was zero, insert a record based on the code I search for and then return that record back to me.
>
>Thanks for any advice
>
>Kirk
Al Williams

Anola MB, CANADA
Previous
Reply
Map
View

Click here to load this message in the networking platform