【发布时间】:2014-10-05 18:32:21
【问题描述】:
我在尝试INSERT一列中的一个值,结果一个SELECT这句话效果很好:
insert into tempdepa (Trabajadores)
(select count (DepartmentName)
from DimEmployee
where DepartmentName = @d)
但我想将 SELECT 插入特定列:
insert into tempdepa (Trabajadores)
(select count (DepartmentName)
from DimEmployee
where DepartmentName = @d)
其中 id = @cont
最后一个where id = @cont 来自第一个表(tempdepa)...我试过了
insert into tempdepa (Trabajadores where id = @cont)
(select count (DepartmentName)
from DimEmployee
where DepartmentName = @d)
但它不起作用。我该怎么做?
【问题讨论】:
-
不清楚,但我认为你需要一个 JOIN。
-
如果您想更改现有行的值,您可能需要使用
UPDATE而不是INSERT!INSERT不能用WHERE子句“参数化” - 它只是插入一个新行。
标签: sql sql-server select insert