我现在要拷贝选指定单位编码的所有记录,变成其他单位的数据。我想select 出记录后 ,更新了单位编码后在insert回去,但是不知道SQL怎么写,请会的朋友帮帮忙,谢谢~!

解决方案 »

  1.   

    select * from tb where 单位='爱仕达'insert tb
    select '新的单位编码' ,其他列 from tb where  单位='爱仕达' 
      

  2.   


    CREATE table tb(id int,note varchar(100))
    go
    insert into tb(id,note) values(1,'aaa')
    insert into tb(id,note) values(1,'bbb')
    insert into tb(id,note) values(2,'ccc')
    select * from tb--查看结果1
    insert into tb select 2,note from tb where id = 1
    select * from tb--查看结果2
    drop table tb结果1:
    id          note
    ----------- ------------
    1           aaa
    1           bbb
    2           ccc
    结果2:
    id          note
    ----------- ------------
    1           aaa
    1           bbb
    2           ccc
    2           aaa
    2           bbb
    是你想要的结果吗?
      

  3.   

    最好给出完整的表结构,测试数据,计算方法和正确结果.否则耽搁的是你宝贵的时间。
    如果有多表,表之间如何关联?
    发帖注意事项
    http://topic.csdn.net/u/20091130/21/fb718680-98ff-4afb-98d8-cff2f8293ed5.html?24281
      

  4.   

    这个不是一个语句执行就可以的。页面上输入单位编号 点查询执行 select * from table where 单位='输入的单位'然后输入新单位编号,例如 新单位执行 
    insert into table
    select '新单位',col1,col2 from table where  单位='输入的单位'declare @table table (id int,col varchar(1),col1 varchar(6))
    insert into @table
    select 1,'a','a1' union all
    select 2,'b','a2' union all
    select 3,'c','a3'select * from @table where col='a'
    /*
    id          col  col1
    ----------- ---- ------
    1           a    a1
    */--把a变成g再插入:
    insert into @table
    select id,'g',col1 from @table where col='a'select * from @table
    /*
    id          col  col1
    ----------- ---- ------
    1           a    a1
    2           b    a2
    3           c    a3
    1           g    a1
    */