@cd1 int,
@cd2 int,
@val01 int,
@val02 int,
@val03 int,
@val04 int,
@val05 int;
Declare @T_TST2 table(cd3 int not null,val char(1))
insert into @T_TST2(cd3,val)
select cd3,val from T_TST2 where cd1 = '101' and cd2 = '1002';
declare cr1 cursor for
select cd1,cd2,val01,val02,val03,val04,val05 from T_TST1
where cd1 = '101' and cd2 = '1002';
open cr1
fetch next from cr1 into @cd1,@cd2,@val01,@val02,@val03,@val04,@val05
while @@fetch_status = 0
begin
select @cd1,@cd2,
case @val01
when 0 then '*'
else (select val from @T_TST2 t where t.cd3 = @val01) end,
case @val02
when 0 then '*'
else (select val from @T_TST2 t where t.cd3 = @val02) end,
case @val03
when 0 then '*'
else (select val from @T_TST2 t where t.cd3 = @val03) end,
case @val04
when 0 then '*'
else (select val from @T_TST2 t where t.cd3 = @val04) end,
case @val05
when 0 then '*'
else (select val from @T_TST2 t where t.cd3 = @val05) end;
fetch next from cr1 into @cd1,@cd2,@val01,@val02,@val03,@val04,@val05
end
close cr1
deallocate cr1
select出来的3条数据分别发到3个表里面了。
我现在想把这3条数据放在1个表里,该怎么改?