有四个表gz(工资表),gz_jxkq(考勤机导出的数据),xsryb(每个人中夜班费标准),xsbzb(具体标准)。 ---------------------------------------------------------------------------------------------------------- |
答案: |
SQL code
declare @string nvarchar(2000) declare @bianhao varchar(6) declare youbiao cursor for select 编号 from gz open youbiao fetch next from youbiao into @bianhao while @@fetch_status=0 begin select @string= ' update a '+ 'set '+d.中班标准+'='+cast(b.中班 as varchar(2))+', ' +d.夜班标准+'='+cast(b.夜班 as varchar(2)) +N' from GZ a,GZ_jxkq b,xsryb c,xsbzb d where a.编号=b.工资号 and a.姓名=c.姓名 and c.享受序号=d.序号 and a.编号='+''''+@bianhao+'''' from GZ a,GZ_jxkq b,xsryb c,xsbzb d where a.编号=b.工资号 and a.姓名=c.姓名 and c.享受序号=d.序号 and a.编号=@bianhao
exec(@string) fetch next from youbiao into @bianhao end
close youbiao deallocate youbiao |