我建立一個存儲過程。如果具有特定值的記錄不存在,則此存儲過程需要插入記錄。如果該值確實存在,則需要更新記錄。我遇到的問題是確定具有給定值的記錄是否存在。我正在使用以下代碼:SQL - 計數返回的記錄
DECLARE @record1ID as char(36)
SET @record1ID = (SELECT TOP 1 ID FROM Person WHERE [Role]='Manager')
DECLARE @record2ID as char(36)
SET @record2ID = (SELECT TOP 1 d.ID FROM Department d WHERE d.[ManagerID][email protected])
-- If @record2ID is set update record, otherwise add record
-- how do I setup this if/else statement?
謝謝!