求一个语句~~

kaper 2008-02-01 12:50:56
declare @i int
set @i=0

insert into t_barcode(barcode)
select @i from t_art where productID='0001'


我想让@i递增(从1开始) 要怎么写? 不要用游标, 速度太慢了,

insert后t_barcode表的内容是:

barcode
1
2
3
4
5
6
7
。。。
。。。
...全文
92 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wzy_love_sly 2008-02-01
  • 打赏
  • 举报
回复
declare   @i   int  
set @i=0
while @i<=20
begin
print @i
set @i=@i+1
end
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
hyit2004 2008-02-01
  • 打赏
  • 举报
回复
Create table #t
(a int, b varchar(10))
insert into #t(a)
select 9 as A union select 11 unionselect 22 union
select 5 union select 33
---sql 2005
select ROW_NUMBER() OVER (order by a )as b, a from #t
--sql 2000
select a,b=identity(int,1,1) into #t1 from #t

select * from #t

update a
set b=(select count(*) from #t where a<=a.a)
from #t a
elvis_gao 2008-02-01
  • 打赏
  • 举报
回复
描述的不太清楚
god_is_man 2008-02-01
  • 打赏
  • 举报
回复
declare @i int
set @i=0
while @i<=20
begin
print @i
set @i=@i+1
end
-狙击手- 2008-02-01
  • 打赏
  • 举报
回复
create table t_barcode(barcode int)
create table t_art(productid varchar(10))
go

insert t_art select '0001'
insert t_art select '0001'
insert t_art select '0001'
insert t_art select '0001'
insert t_art select '0001'

declare @i int
set @i=0
select px=identity(int,1,1) into # from t_art where productID='0001'
insert into t_barcode(barcode)
select px from #

select * from t_barcode
drop table t_barcode,t_art,#

/8
barcode
-----------
1
2
3
4
5

(所影响的行数为 5 行)
*/

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧