insert into b(aa,bb) select aa,bb from a
解决方案 »
- 这个SQL怎么写
- 请教个数据复制插入的sql语句写法
- SqlServer sp4安装时问题
- 在sqlserver中怎样把字符串转换成“yyyy/mm/dd”的形式
- sqlserver2000中,能否查到数据库的连接状态,在线等。
- 数据库还原不了,截了个图,大家帮看是什么回事
- sqlserver 2005 中文字符查询问题
- 请问用怎样用vb6编程实现将客户端与SQL Server7的连接为TCP/IP方式,而非named pipes?
- 朋友请教,一定给分。(SQL语言应用问题)
- 急求,master数据库恢复!!!!
- 同一服务器,不同数据库,如何实现跨库视图的编写?
- 这个视图怎么建,在线等,实时给分
declare @i int
set @i=0
insert into b(xx,aa,bb) select @i=@i+1,aa,bb from a
如果是
insert into b (aa,bb)
select aa,bb from a
insert into b (xx,aa,bb) select xx,aa,bb from #t
drop table #t
insert into b (xx,aa,bb) select xx,aa,bb from #t
drop table #t
不知道你的编号有什么规律还是从别的表关联得到,如果是关联得到,可以用update
update b
set xx=..
from b,其他表
where ....
declare @i int
insert into b(xx,bb,aa) select @i=@i+1,bb,aa from a
select identity(int,1,1) as xx,aa,bb into #t from a
insert into b (xx,aa,bb) select cast(xx as varchar),aa,bb from #t
drop table #t
如果#t的编号和b中的编号重复怎么办?
insert b(xx,aa,bb) select 0,aa,bb from a--再生成xx
declare @i int
set @i=0
update b set @i=@i+1,xx=@i
insert b(xx,aa,bb) select 0,aa,bb from a--再生成xx
declare @i int
selectt @i=max(xx0 from b
update b set @i=@i+1,xx=@i
where xx=0
我理解的楼主的意思是b表没有数据,如果有数据,楼主应该指明
from #t a,(select id=max(xx) from b)bdrop table #t
insert b(xx,aa,bb) select 0,aa,bb from a--再生成xx
declare @i int
selectt @i=max(xx) from b --这里原来写错了.
update b set @i=@i+1,xx=@i
where xx=0