我有一个存储过程,可以将一些行插入表中。有时它似乎会失败(找不到新记录),尽管我知道语句确实执行了。我使用的代码如下。执行后,我可以在 tbl_DebugLog 表中找到相关行,但在 tbl_WebSiteNotifications 表中找不到。我使用的是 SQL Server 15.0.2。此外,该表是合并复制的一部分。什么会导致这种情况?
insert into tbl_WebSiteNotifications(NotificationType, FileID, UserID, SubscriptionID, InsertionDate)
select RequestType, FileID, UserID, SubscriptionID, DateRequested
from #TempNotifications
where UserID is not null
insert into tbl_DebugLog (LogDate, LogMessage, ServerName)
select getdate(), 'FileID ' + format(FileID,'D') + N' for SubscriptionID ' + format (SubscriptionID,'D') + N' Inserted into tbl_WebSiteNotifications' +
', NotificationType=' + format(RequestType,'D') +
', UserID=' + format(UserID,'D') +
', InsertionDate=' + format(DateRequested,'dd-MM-yyyy'),
@@SERVERNAME
from #TempNotifications
where UserID is not null