我在sql server
是新和嘗試,除了導致到表爲目的插入寫這樣的代碼:
如何將sql server除結果保存到表中?
insert into [tablediff].[dbo].[TempTable]
select [Phone] from [dbo].[CRMSubscriber]
except
select [Phone] from [dbo].[BillingSubscriber]
代碼工作很好,但是當我嘗試運行此代碼:
use [tablediff]
if (not exists(
insert into [tablediff].[dbo].[TempTable]
select [Phone] from [dbo].[CRMSubscriber]
except
select [Phone] from [dbo].[BillingSubscriber]
))
begin
print 'no record'
end
else
begin
print 'has record'
end
得到這個錯誤:
Msg 156, Level 15, State 1, Line 3 Incorrect syntax near the keyword 'insert'.
Msg 102, Level 15, State 1, Line 7 Incorrect syntax near ')'.
Msg 156, Level 15, State 1, Line 11 Incorrect syntax near the keyword 'else'.
我該如何解決這個問題?謝謝。
我認爲,這是[MERGE](https://docs.microsoft.com/en-us/sql/t-sql/statements/merge-transact-sql)你想重新什麼發明... – Shnugo
@Shnugo感謝我的朋友注意我的問題,我想告訴用戶什麼區別來源和目的地表或更exmplain哪些記錄到CRM表中,而不是在結算表 –
您可以使用'OUTPUT'語句來獲得持續的更改列表......或者您可以使用「@@ ROWCOUNT」獲取最後一個操作的受影響行數。 – Shnugo