如何将此Access Query表示为SQL Server查询

时间:2014-08-24 17:04:46

标签: sql sql-server ms-access

我有一个访问数据库,但最近搬到了SQL服务器,我几乎修改了所有查询但是这个:

UPDATE Articulos_Auditoria 
INNER JOIN Auditoria ON Articulos_Auditoria.CUD = Auditoria.CUD 
SET Articulos_Auditoria.Cortado = 'True' 
WHERE 
   (((CAST([Fecha] AS DATE)) = CAST(@Fecha AS DATE)) 
    AND ((Auditoria.Terminal) = @term))

我正在尝试将其转换为SQL Server(因为我将DateValue更改为CAST)但是intellisense在“' INNER'

附近给出了语法错误

有人能给我一些见解吗?

2 个答案:

答案 0 :(得分:1)

使用from子句和表别名:

UPDATE aa
    SET Cortado = 'True'
    FROM Articulos_Auditoria aa INNER JOIN
         Auditoria a
         ON aa.CUD = a.CUD 
    WHERE CAST([Fecha] as date) = CAST(@Fecha as date) AND (a.Terminal = @term)

答案 1 :(得分:1)

您有两个错误:

  1. 您需要在SET

  2. 之后定义UPDATE TableName
  3. 您需要定义FROM子句

    UPDATE Articulos_Auditoria 
           SET Cortado = 'True'
    FROM   Articulos_Auditoria 
           INNER JOIN Auditoria 
               ON Articulos_Auditoria.CUD = Auditoria.CUD 
    WHERE  CAST([Fecha] as date)=CAST(@Fecha as date) 
           AND Auditoria.Terminal=@term