0

我有一个脚本,它克隆数据库模式(表)并添加一些列来跟踪数据更改(我们经常从遗留 ​​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

预先感谢您提供的任何帮助

4

1 回答 1

2

您的代码中没有语法错误。您的数据库的兼容级别为SQL Server 2005 (90)或更低。它需要SQL Server 2008 (100)或更高。

ALTER DATABASE 兼容级别 (Transact-SQL)

于 2013-01-19T11:42:39.657 回答