如何将少量记录从表更新到另一个表

时间:2013-09-17 09:24:24

标签: sql sql-server sql-server-2008

我想使用where子句将少量记录从test table更新到testResult表,如下所示,但我得到了所有唯一值。我知道为什么我会这样。

UPDATE       testResult
SET                TRM = te.TRM, timeStamp = te.timeStamp, FWD = te.FWD, OverAll = te.OverAll, ExRFln = te.ExRFln, ExDuty = te.ExDuty, VSWR = te.VSWR, REVPWR = te.REVPWR, 
                         coordinateA = te.coordinateA, coordinateB = te.coordinateB
FROM            test AS te CROSS JOIN
                         testResult
WHERE        (te.timeStamp BETWEEN CONVERT(datetime, '2013-09-05 18:23:50', 120) AND CONVERT(datetime, '2013-09-05 18:24:59', 120))

所有列都有与测试表对应的唯一数据,其中timeStamp是2013-09-05 18:23:50

这是显示列值的测试表截图

enter image description here

这是执行后显示的testResult屏幕截图

enter image description here

1 个答案:

答案 0 :(得分:0)

我认为你可以实现你想要的目标:

select *
into   testResult
from   test
where  timeStamp BETWEEN CONVERT(datetime, '2013-09-05 18:23:50', 120) AND 
       CONVERT(datetime, '2013-09-05 18:24:59', 120)

(仅当testResult表尚不存在时才会起作用)