Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 21st, 2012  |  syntax: None  |  size: 0.83 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Update with a cursor in SQL Server 2008 R2
  2. DECLARE @l_profiel int;
  3. DECLARE c1 CURSOR  
  4. FOR select p.ProfielID
  5. from DIM_Profiel p,DIM_EmployeeKopie1 e1,employee e
  6. where e1.EmpidOrigineel = e.emplid and e.profile_code = p.Prof_Code
  7. for update of e1.FK_Profiel;
  8. open c1;
  9. FETCH NEXT FROM c1 into @l_profiel
  10. WHILE @@FETCH_STATUS = 0
  11. BEGIN
  12. SET NOCOUNT ON;
  13.         UPDATE DIM_EmployeeKopie1
  14.         set FK_Profiel = @l_profiel
  15.         where current of c1
  16.  
  17. end
  18.  
  19. close c1;
  20. deallocate c1;
  21.        
  22. UPDATE  e1
  23. SET     FK_Profiel = p.ProfielID
  24. FROM    DIM_EmployeeKopie1 e1
  25. JOIN    employee e
  26. ON      e.emplid = e1.EmpidOrigineel
  27. JOIN    DIM_Profiel p
  28. ON      p.Prof_Code = e.profile_code
  29.        
  30. UPDATE e1
  31. SET FK_Profiel = p.ProfielID
  32. FROM DIM_EmployeeKopie1 e1
  33. JOIN employee e
  34. ON e1.EmpidOrigineel = e.emplid
  35. JOIN DIM_Profiel p
  36. ON e.profile_code = p.Prof_Code