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
 Request support on writing insert/update sp!

Author  Topic 

petre
Starting Member

11 Posts

Posted - 2010-06-19 : 06:56:59
hi friend,
i was trying to write an inser_update sp that handles cocurrencies. but i wrote it on several ways in either there is bugs (logic errors) so the control doesn't flow the way i wanted. I have an image of flow of control, if i pubslish that would you be able to write this stored procedure that i was trying to write for days and day.

this is very simple for nakid eye but gets complicated with the control structure, the requriement is
to write a sp that does insert and update operations both.

the table sp works on has thrww columns, idx int auto, code char(6)unique not null, rversion timestamp not null

SP should check the following:
when insert
1. is fresh or existing
2. does the entering record has a duplicate value for code
3. if all above passed enter the record

when update:
1. check the record exists before update
2. check weather it handles concurrencies

PS i use SQL express 2005

cheers

PS> im not a db developer

Kristen
Test

22859 Posts

Posted - 2010-06-19 : 07:59:46
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=56148 - UpSert with "hint" to force INSERT or UPDATE when EXISTS is known

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=72835 - Perform either INSERT or UPDATE and if "fail" revert to the other

SQL2005 onwards you can use the MERGE statement for "UpSerts"
Go to Top of Page
   

- Advertisement -