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.
| Author |
Topic |
|
tpiazza55
Posting Yak Master
162 Posts |
Posted - 2008-01-22 : 09:42:09
|
| Im trying to keep a mirror image of some data Im getting from Quickbooks.As the records are inserted into the database I need to check if a record exists and either update or insert a new one.it seems easier just to delete using the tnxid and reinsert vs updatingmy question is if I gobeginINSERT INTO QBInvoicesQue(100s of feilds) endbegin delete from QBInvoices where txnid = @TxnIDendand there is not matching txnid to delete from will it cause any problems? before going to the insert statement?beginINSERT INTO QBInvoices(100s of feilds) end |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-01-22 : 09:44:30
|
IF EXISTS(SELECT * FROM QBInvoices WHERE txnid = @TxnID) UPDATE ...ELSE INSERT ... E 12°55'05.25"N 56°04'39.16" |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
|
|
tpiazza55
Posting Yak Master
162 Posts |
Posted - 2008-01-22 : 09:54:29
|
| is there any disadvantage to IF EXISTS(SELECT * FROM QBInvoices WHERE txnid = @TxnID)begindelete from QBInvoices where txnid = @TxnIDINSERT INTO QBInvoices(stuff)end |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2008-01-22 : 09:58:43
|
| why would you want to do that when you can update?_______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenpSSMS Add-in that does a few things: www.ssmstoolspack.com <- new version out |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-01-22 : 10:00:00
|
As Spirit is pointing out, there could potentially be a problem with [dead]locks. E 12°55'05.25"N 56°04'39.16" |
 |
|
|
tpiazza55
Posting Yak Master
162 Posts |
Posted - 2008-01-22 : 10:14:12
|
| its literally a hundred field -- guess i need to update to avoid the dead lock |
 |
|
|
|
|
|