比如存在表a1 包括2列 id,apply_type,将数据逐行插入B
declare @myid int
decalre @app nvarchar(50)
declare mycursor cursor for
select id,apply_type from a1 >>声明游标
open mycursor >>打开游标
fetch next from mycursor into @myid,@app
while @@fetch_status=0
begin
要对数据怎么处理可自己添加
insert into b values(@myid,@app) >>这是做插入操作
fetch next from mycursor into @yhid,@app >>继续读a1下条数据
end
close mycursor >>关闭游标
deallocate mycursor >>释放游标
你是想得到显示的数据,还是想从新建一个表。感觉你用多表关联就可以了吧,或者你用视图将处理的数据存放在视图里面。
查询插入 select into (关键还是看你怎么处理)
用游标