データベース スキーマ (テーブル) を複製し、いくつかの列を追加してデータの変更を追跡するスクリプトを用意しました (従来の ERP からデータを受け取ることがよくあります)。このスクリプトは、データの変更をチェックするストアド プロシージャをいくつか作成します。それは常に魅力的に機能しましたが、今日、テストデータベースで起動した後、エラーが発生しました:
メッセージ 102、レベル 15、状態 1、プロシージャ COMPUTE_AGENT、行 9
'.' 付近の構文が正しくありません
手順は次のとおりです。
CREATE PROCEDURE [dbo].[COMPUTE_AGENT] (@Debug INT = 0)
AS
BEGIN
DECLARE @Actions TABLE (IUD VARCHAR(100))
INSERT INTO @Actions (IUD)
SELECT IUD
FROM (
MERGE [frontier].[AGENT] AS [Destination]
USING [dbo].[AGENT] AS [Source]
ON [Destination].[AgentCode] = [Source].[AgentCode]
WHEN NOT MATCHED BY TARGET
THEN
INSERT (
[AgentCode]
,[Name]
,[PersonalTaxCode]
,[VatNumber]
,[Commission]
,[Address]
,[City]
,[ZipCode]
,[Province]
,[Region]
,[Country]
,[Phone]
,[CellPhone]
,[FAX]
,[EMail]
,[Web]
,[LastEditDate]
,[CHECKSUM]
,[SyncroLED]
,[SyncroPS]
)
VALUES (
[Source].[AgentCode]
,[Source].[Name]
,[Source].[PersonalTaxCode]
,[Source].[VatNumber]
,[Source].[Commission]
,[Source].[Address]
,[Source].[City]
,[Source].[ZipCode]
,[Source].[Province]
,[Source].[Region]
,[Source].[Country]
,[Source].[Phone]
,[Source].[CellPhone]
,[Source].[FAX]
,[Source].[EMail]
,[Source].[Web]
,[Source].[LastEditDate]
,BINARY_CHECKSUM([Source].[AgentCode], [Source].[Name], [Source].[PersonalTaxCode], [Source].[VatNumber], [Source].[Commission], [Source].[Address], [Source].[City], [Source].[ZipCode], [Source].[Province], [Source].[Region], [Source].[Country], [Source].[Phone], [Source].[CellPhone], [Source].[FAX], [Source].[EMail], [Source].[Web], [Source].[LastEditDate])
,GETDATE()
,0
)
WHEN MATCHED
AND [Destination].[CHECKSUM] <> BINARY_CHECKSUM([Source].[AgentCode], [Source].[Name], [Source].[PersonalTaxCode], [Source].[VatNumber], [Source].[Commission], [Source].[Address], [Source].[City], [Source].[ZipCode], [Source].[Province], [Source].[Region], [Source].[Country], [Source].[Phone], [Source].[CellPhone], [Source].[FAX], [Source].[EMail], [Source].[Web], [Source].[LastEditDate])
THEN
UPDATE
SET [Destination].[AgentCode] = [Source].[AgentCode]
,[Destination].[Name] = [Source].[Name]
,[Destination].[PersonalTaxCode] = [Source].[PersonalTaxCode]
,[Destination].[VatNumber] = [Source].[VatNumber]
,[Destination].[Commission] = [Source].[Commission]
,[Destination].[Address] = [Source].[Address]
,[Destination].[City] = [Source].[City]
,[Destination].[ZipCode] = [Source].[ZipCode]
,[Destination].[Province] = [Source].[Province]
,[Destination].[Region] = [Source].[Region]
,[Destination].[Country] = [Source].[Country]
,[Destination].[Phone] = [Source].[Phone]
,[Destination].[CellPhone] = [Source].[CellPhone]
,[Destination].[FAX] = [Source].[FAX]
,[Destination].[EMail] = [Source].[EMail]
,[Destination].[Web] = [Source].[Web]
,[Destination].[LastEditDate] = [Source].[LastEditDate]
,[Destination].[CHECKSUM] = BINARY_CHECKSUM([Source].[AgentCode], [Source].[Name], [Source].[PersonalTaxCode], [Source].[VatNumber], [Source].[Commission], [Source].[Address], [Source].[City], [Source].[ZipCode], [Source].[Province], [Source].[Region], [Source].[Country], [Source].[Phone], [Source].[CellPhone], [Source].[FAX], [Source].[EMail], [Source].[Web], [Source].[LastEditDate])
,[Destination].[SyncroLED] = GETDATE()
,[Destination].[SyncroPS] = 0
WHEN NOT MATCHED BY SOURCE
AND [Destination].[SyncroPS] <> 1
THEN
UPDATE
SET [Destination].[SyncroPS] = 1
,[Destination].[SyncroLED] = GETDATE()
OUTPUT $ACTION
) AS TheMerge(IUD)
IF @Debug = 1
SELECT IUD AS [Action]
,COUNT(IUD) AS [Count]
FROM @Actions
GROUP BY IUD
END
エラーがどこにあるのかよくわかりません。エラーが発生することなく、他の多くのデータベースで同じスクリプトを起動しようとしました...これは本当に私を怒らせており、問題はおそらく些細なことであり、私はそれを見つけることができないので本当に愚かだと感じています...
エラーを発生させない別の自動生成プロシージャを次に示します(別のデータベースから生成):
CREATE PROCEDURE [dbo].[COMPUTE_Agente] (@Debug INT = 0)
AS
BEGIN
DECLARE @Actions TABLE (IUD VARCHAR(100))
INSERT INTO @Actions (IUD)
SELECT IUD
FROM (
MERGE [frontier].[Agente] AS [Destination]
USING [dbo].[Agente] AS [Source]
ON [Destination].[CodiceAgente] = [Source].[CodiceAgente]
WHEN NOT MATCHED BY TARGET
THEN
INSERT (
[CodiceAgente]
,[Nome]
,[CodiceFiscale]
,[PartitaIVA]
,[Provvigioni]
,[Indirizzo]
,[Localita]
,[CAP]
,[Provincia]
,[Regione]
,[Nazione]
,[Telefono]
,[Cellulare]
,[Fax]
,[EMail]
,[SitoWeb]
,[DataModifica]
,[CHECKSUM]
,[SyncroLED]
,[SyncroPS]
)
VALUES (
[Source].[CodiceAgente]
,[Source].[Nome]
,[Source].[CodiceFiscale]
,[Source].[PartitaIVA]
,[Source].[Provvigioni]
,[Source].[Indirizzo]
,[Source].[Localita]
,[Source].[CAP]
,[Source].[Provincia]
,[Source].[Regione]
,[Source].[Nazione]
,[Source].[Telefono]
,[Source].[Cellulare]
,[Source].[Fax]
,[Source].[EMail]
,[Source].[SitoWeb]
,[Source].[DataModifica]
,BINARY_CHECKSUM([Source].[CodiceAgente], [Source].[Nome], [Source].[CodiceFiscale], [Source].[PartitaIVA], [Source].[Provvigioni], [Source].[Indirizzo], [Source].[Localita], [Source].[CAP], [Source].[Provincia], [Source].[Regione], [Source].[Nazione], [Source].[Telefono], [Source].[Cellulare], [Source].[Fax], [Source].[EMail], [Source].[SitoWeb], [Source].[DataModifica])
,GETDATE()
,0
)
WHEN MATCHED
AND [Destination].[CHECKSUM] <> BINARY_CHECKSUM([Source].[CodiceAgente], [Source].[Nome], [Source].[CodiceFiscale], [Source].[PartitaIVA], [Source].[Provvigioni], [Source].[Indirizzo], [Source].[Localita], [Source].[CAP], [Source].[Provincia], [Source].[Regione], [Source].[Nazione], [Source].[Telefono], [Source].[Cellulare], [Source].[Fax], [Source].[EMail], [Source].[SitoWeb], [Source].[DataModifica])
THEN
UPDATE
SET [Destination].[CodiceAgente] = [Source].[CodiceAgente]
,[Destination].[Nome] = [Source].[Nome]
,[Destination].[CodiceFiscale] = [Source].[CodiceFiscale]
,[Destination].[PartitaIVA] = [Source].[PartitaIVA]
,[Destination].[Provvigioni] = [Source].[Provvigioni]
,[Destination].[Indirizzo] = [Source].[Indirizzo]
,[Destination].[Localita] = [Source].[Localita]
,[Destination].[CAP] = [Source].[CAP]
,[Destination].[Provincia] = [Source].[Provincia]
,[Destination].[Regione] = [Source].[Regione]
,[Destination].[Nazione] = [Source].[Nazione]
,[Destination].[Telefono] = [Source].[Telefono]
,[Destination].[Cellulare] = [Source].[Cellulare]
,[Destination].[Fax] = [Source].[Fax]
,[Destination].[EMail] = [Source].[EMail]
,[Destination].[SitoWeb] = [Source].[SitoWeb]
,[Destination].[DataModifica] = [Source].[DataModifica]
,[Destination].[CHECKSUM] = BINARY_CHECKSUM([Source].[CodiceAgente], [Source].[Nome], [Source].[CodiceFiscale], [Source].[PartitaIVA], [Source].[Provvigioni], [Source].[Indirizzo], [Source].[Localita], [Source].[CAP], [Source].[Provincia], [Source].[Regione], [Source].[Nazione], [Source].[Telefono], [Source].[Cellulare], [Source].[Fax], [Source].[EMail], [Source].[SitoWeb], [Source].[DataModifica])
,[Destination].[SyncroLED] = GETDATE()
,[Destination].[SyncroPS] = 0
WHEN NOT MATCHED BY SOURCE
AND [Destination].[SyncroPS] <> 1
THEN
UPDATE
SET [Destination].[SyncroPS] = 1
,[Destination].[SyncroLED] = GETDATE()
OUTPUT $ACTION
) AS TheMerge(IUD)
IF @Debug = 1
SELECT IUD AS [Action]
,COUNT(IUD) AS [Count]
FROM @Actions
GROUP BY IUD
END
よろしくお願いします。