附件中有3个工作表,我想根据表1和表2的原始数据,通过编程得到表3的数据格式。请各位帮助。
[此贴子已经被作者于2007-9-24 14:21:43编辑过]
附件中有3个工作表,我想根据表1和表2的原始数据,通过编程得到表3的数据格式。请各位帮助。
[此贴子已经被作者于2007-9-24 14:21:43编辑过]
if object_id('table1') is not null
drop table table1
if object_id('table2') is not null
drop table table2
if object_id('table3') is not null
drop table table3
go
create table table1(
psid int,
psnum int
)
insert into table1(psid,psnum)
select 8186000,8186000 union all
select 8186001,8186001 union all
select 8186002,8186002 union all
select 8186003,8186003 union all
select 8186004,8186004 union all
select 8186005,8186005 union all
select 8186006,8186006 union all
select 8186007,8186007 union all
select 8186008,8186008 union all
select 8186009,8186009 union all
select 8186010,8186010 union all
select 8186011,8186011 union all
select 8186012,8186012 union all
select 8186013,8186013 union all
select 8186014,8186014 union all
select 8186015,8186015 union all
select 8186016,8186016 union all
select 8186017,8186017 union all
select 8186018,8186018 union all
select 8186019,8186019
go
create table table2(
psid int
)
insert into table2(psid)
select 8186001 union all
select 8186005 union all
select 8186010 union all
select 8186014 union all
select 8186018
go
create table table3(
psid int,
psnum int
)
insert into table3(psid)
select 8186000 union all
select 8186001 union all
select 8186002 union all
select 8186003 union all
select 8186004 union all
select 8186005 union all
select 8186006 union all
select 8186007 union all
select 8186008 union all
select 8186009 union all
select 8186010 union all
select 8186011 union all
select 8186012 union all
select 8186013 union all
select 8186014 union all
select 8186015 union all
select 8186016 union all
select 8186017 union all
select 8186018 union all
select 8186019
go
update table3 set table3.psnum=(select table1.psnum from table1 where table1.psid=table2.psid)
from table2
where table3.psid=table2.psid
select * from table3