合并在sql server 2008 r2中

时间:2022-12-27 03:39:01

I am executing the following merge statement in SQL Server 2008

我在SQL Server 2008中执行以下合并语句

MERGE Nuevo_Nav AS a
USING Tabla_correcta AS b
ON a.[No_] = b.[No_ Documento]
WHEN MATCHED THEN
    UPDATE SET a.[Respuesta CAE_CAEC] = b.[Respuesta CAE_CAEC]; 

I have the following error:

我有以下错误:

Msg 156, Level 15, State 1, Line 1 Incorrect syntax near the keyword 'as'.

消息156,级别15,状态1,行1关键字'as'附近的语法不正确。

2 个解决方案

#1


1  

This is a guess, but are you running this in a multi-statement batch/sproc, etc? If so, make sure there is a semi-colon before the beginning of the merge statement. That's a new requirement when the merge statement was introduced in SQL 2008. So:

这是猜测,但你是在多语句批处理/ sproc等中运行它吗?如果是这样,请确保在merge语句开头之前有一个分号。在SQL 2008中引入merge语句时,这是一个新要求。所以:

;MERGE INTO Blah
USING Blah2...
SET Blah.a = Blah2.b;

or

DECLARE @str VARCHAR(1000) = 'This is my previous code line';

MERGE INTO Blah
USING Blah2...
SET Blah.a = Blah2.b;

I forget this every once in a while, since semi-colons after every statement aren't mandatory in most cases.

我偶尔会忘记这一点,因为在大多数情况下,每个陈述后的分号都不是强制性的。

#2


0  

Like Fireblade said, you don't need a MERGE here. This is a simple UPDATE.

就像Fireblade说的那样,你在这里不需要MERGE。这是一个简单的更新。

UPDATE a
SET a.[Respuesta CAE_CAEC] = b.[Respuesta CAE_CAEC]
FROM Nuevo_Nav a
INNER JOIN Tabla_correcta b
  ON a.[No_] = b.[No_ Documento]

#1


1  

This is a guess, but are you running this in a multi-statement batch/sproc, etc? If so, make sure there is a semi-colon before the beginning of the merge statement. That's a new requirement when the merge statement was introduced in SQL 2008. So:

这是猜测,但你是在多语句批处理/ sproc等中运行它吗?如果是这样,请确保在merge语句开头之前有一个分号。在SQL 2008中引入merge语句时,这是一个新要求。所以:

;MERGE INTO Blah
USING Blah2...
SET Blah.a = Blah2.b;

or

DECLARE @str VARCHAR(1000) = 'This is my previous code line';

MERGE INTO Blah
USING Blah2...
SET Blah.a = Blah2.b;

I forget this every once in a while, since semi-colons after every statement aren't mandatory in most cases.

我偶尔会忘记这一点,因为在大多数情况下,每个陈述后的分号都不是强制性的。

#2


0  

Like Fireblade said, you don't need a MERGE here. This is a simple UPDATE.

就像Fireblade说的那样,你在这里不需要MERGE。这是一个简单的更新。

UPDATE a
SET a.[Respuesta CAE_CAEC] = b.[Respuesta CAE_CAEC]
FROM Nuevo_Nav a
INNER JOIN Tabla_correcta b
  ON a.[No_] = b.[No_ Documento]