SQLserver 在同一个表中,怎么把一列中的某些字段复制到另一列中的同一个字段下

表中有id,pbillno,A,B,C,D这几个字段,id的值为1到7 id=1这记录的ABCD 复制到id=0的记录中 pbillno字段相同的
表中有id,pbillno,A,B,C,D这几个字段,id的值为1到7 id=1这记录的ABCD 复制到id=0的记录的ABCD中 其中pbillno字段相同的

如ID=1的内容复制到ID=0的内容,这样就行了
update b
set b.A=a.A,b.B=a.B,b.C=a.C,b.D=a.D
from tableA as a,TableA as b
where a.ID=1 and a.ID=b.ID+1
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2018-04-19
update XXX set a=(select a from XXX where id=1) where id=0;

update XXX set b=(select b from XXX where id=1) where id=0;

update XXX set c=(select c from XXX where id=1) where id=0;

如果id=2的值与id=1的值只有id字段不同的话,可以用
insert into XXX (select 2,pbillno_value,a,b,c,d from XXX)本回答被网友采纳
第2个回答  2012-07-18
试试这个吧:

update tab set a=tab2.a,b=tab2.b,c=tab2.c,d=tab2.d
from (select a,b,c,d,id where id = 1) tab2
where id = 0追问

你这是在同一个表中吗?

追答

是同一个表,不过么有写全,入校:

update tab set a=tab2.a,b=tab2.b,c=tab2.c,d=tab2.d
from (select a,b,c,d,id from tab where id = 1) tab2
where id = 0

相似回答