使用另一个表中的数据更新sql表列

时间:2013-08-30 06:58:24

标签: sql-server tsql

UPDATE [APL4_WATERPLANT].[dbo].[PRINT_PWD] 
SET [APL4_WATERPLANT].[dbo].[PRINT_PWD].[CLT_2101] = ([APL4_WATERPLANT].[dbo].[PWD].[CLT_2101] 
FROM [APL4_WATERPLANT].[dbo].[PWD] 
WHERE [APL4_WATERPLANT].[dbo].[PWD].[DATEANDTIME] = '2013-8-13 12:00:00.000')

每当我尝试执行此代码时,都会收到错误消息。可能是什么问题?

2 个答案:

答案 0 :(得分:1)

我认为子查询中缺少select: -

UPDATE    [APL4_WATERPLANT].[dbo].[PRINT_PWD] 
SET       [APL4_WATERPLANT].[dbo].[PRINT_PWD].[CLT_2101] = 
          (
              select  [APL4_WATERPLANT].[dbo].[PWD].[CLT_2101] 
              FROM    [APL4_WATERPLANT].[dbo].[PWD] 
              WHERE   [APL4_WATERPLANT].[dbo].[PWD].[DATEANDTIME] = '2013-8-13 12:00:00.000'
          )

答案 1 :(得分:1)

试试这个

 UPDATE [APL4_WATERPLANT].[dbo].[PRINT_PWD] 
 SET [APL4_WATERPLANT].[dbo].[PRINT_PWD].[CLT_2101] = (select CLT_2101 
 FROM [APL4_WATERPLANT].[dbo].[PWD] 
 WHERE DATEANDTIME = '2013-8-13 12:00:00.000')