Mar*_*007 1 sql sql-server select insert
我正在尝试INSERT列中的值,SELECT这句话的结果正常:
insert into tempdepa (Trabajadores)
(select count (DepartmentName)
from DimEmployee
where DepartmentName = @d)
Run Code Online (Sandbox Code Playgroud)
但我想将其SELECT插入特定列:
insert into tempdepa (Trabajadores)
(select count (DepartmentName)
from DimEmployee
where DepartmentName = @d)
Run Code Online (Sandbox Code Playgroud)
其中id = @cont
这最后where id = @cont是第一个表(tempdepa)......我试过了
insert into tempdepa (Trabajadores where id = @cont)
(select count (DepartmentName)
from DimEmployee
where DepartmentName = @d)
Run Code Online (Sandbox Code Playgroud)
但它不起作用.我该怎么做?
如果需要插入新行,则需要执行以下操作:
insert into tempdepa (Trabajadores, id)
select count(DepartmentName), @cont
from DimEmployee where DepartmentName = @d
Run Code Online (Sandbox Code Playgroud)
如果你想更新现有的:
update tempdepa
set Trabajadores=(select count (DepartmentName) from DimEmployee where DepartmentName = @d)
where id = @cont
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
136 次 |
| 最近记录: |