我想更新名为Employeekopie1
的特定表中的列。使用SQL Server 2008 R2中的游标更新
我想更新的列是FK_Profiel
(值int
型)
我试图把在列FK_Profiel
的值是我从游标得到 值。游标正在从不同表中的列中获取值,并使用连接来获取正确的值。
使用的select查询的结果返回具有不同值的多行。
选择查询的第一个结果是114,这是正确的。问题是这个值被分配到列FK_Profiel
列中的所有字段,这不是我的意图。
我想分配select查询中的所有值。
的代码如下:
DECLARE @l_profiel int;
DECLARE c1 CURSOR
FOR select p.ProfielID
from DIM_Profiel p,DIM_EmployeeKopie1 e1,employee e
where e1.EmpidOrigineel = e.emplid and e.profile_code = p.Prof_Code
for update of e1.FK_Profiel;
open c1;
FETCH NEXT FROM c1 into @l_profiel
WHILE @@FETCH_STATUS = 0
BEGIN
SET NOCOUNT ON;
UPDATE DIM_EmployeeKopie1
set FK_Profiel = @l_profiel
where current of c1
end
close c1;
deallocate c1;
请帮帮忙,THX。
好了,你打我吧。 +1。 – Lamak 2011-04-20 14:38:50
Woow thx的答案。这解决了我的问题。 – user717316 2011-04-21 07:31:59
行动中的优雅,+1 – Paceman 2016-06-08 03:39:37