Reputation: 2127
I've got a script which clones a database schema (the tables) and adds some columns to keep track of data changes (we often receive data from legacy ERPs), this script creates some stored procedures to check for the changes in the data, it always worked like a charm but today after launching it on a test database it gave me an error:
Msg 102, Level 15, State 1, Procedure COMPUTE_AGENT, Line 9
Incorrect syntax near '.'
This is the procedure:
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
I can't really see where the error is. I tried to launch the same script on many other databases without getting errors... This is really driving me mad and I have the feeling that the problem probably is trivial and i'm really stupid because I can't find it...
Here's another auto-generated procedure which doesn't give any error (generated from another db):
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
Thank you in advance for any help you can give me
Upvotes: 0
Views: 178
Reputation: 138980
There is no syntax error in your code. The compatibility level for your database is SQL Server 2005 (90)
or lower. It needs to be SQL Server 2008 (100)
or higher.
ALTER DATABASE Compatibility Level (Transact-SQL)
Upvotes: 2