我正在嘗試創建一個存盤程序,該程序將在將無效字符插入特定列時或之后向我發送電子郵件。我已經想出了一些腳本來創建它,但我認為我遺漏了一些東西,因為它不斷給我錯誤。我還已經將無效字符確定為 Grave Accent 字符,因此我嘗試使用它,因此當輸入該字符時,我會收到通知。
CREATE PROCEDURE InvalidCharacterCheck
AS
IF ((SELECT * FROM StudentNames WHERE LastName like '%`%') like '%' '`' '%')
BEGIN
EXEC msdb.dbo.sp_send_dbmail
@recipients = '[email protected]',
@subject = 'The LastName column has a record with the grave accent invalid character'
END
ELSE
BEGIN
PRINT 'There is no invalid character in the LastName column at present'
END
uj5u.com熱心網友回復:
你可以嘗試這樣的事情:
CREATE PROCEDURE TestProcedure
AS
BEGIN
DECLARE @errorCount INT;
SELECT
@errorCount = COUNT(FirstName)
FROM
StudentNames
WHERE
FirstName like '%`%'
OR LastName like '%`%'
IF (@errorCount > 0)
BEGIN
EXEC msdb.dbo.sp_send_dbmail @recipients = '[email protected]',
@subject = 'The LastName column has a record with the grave accent invalid character'
END
ELSE
BEGIN
PRINT 'There is no invalid character in the LastName column at present'
END
END
GO
但是,我會著眼于預防而不是治療,并在將資料插入表之前對其進行清理。您不想清理爛攤子,只是一開始就不要創建它。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/496247.html
