[求助]怎样在select中产生序号列 select identity(int,1,1) as 序号, * into #temp from yourtableselect * from #temp 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用identity列或者你在表上加alter table tablename add id int identity(1,1) 首先谢谢两位saucer(思归, MS .NET MVP)的答案能解决我的问题,但第2次执行时会出现临时表已存在的提示,请问怎么解决? happydreamer(小黑-不懂的太多)可能没理解我的意图,我是想在查询出来的结果中出现1,2,3...的序号,如果用id类型的列的话,出来的不一定是从1开始的连续序号 select (select sum(1) from yourtable where name<=tem.name) as no,name from yourtable as tem select (select sum(1) from yourtable where name<=tem.name) as no,* from yourtable as tem select identity(int,1,1) as 序号, * into #temp from yourtableselect * from #tempdrop table #temp--如果是在存储过程里不要这句也可以,临时表会被自动删除 select @i=0select @i=@i+1,* from tablename 若有自增字段idselect (select count(*) from yourtable where id<=tem.id) as no,* from yourtable as tem drop table #tempselect identity(int,1,1) as 序号, * into #temp from yourtableselect * from #temp 执行过程报错 数据库扩充 关键字 'as' 附近有语法错误。 怎样才能显示小数点后面的数字? sql问题 这个变量应该怎么处理;麻烦的单引号 触发器问题(怎样在一个数据库中的触发器中访问另一个数据库里面的表呢) 关于安装sql2000的问题!急~ 求一SQL 急求 SQL 人才 安装SQL2000个人版出错,请大家帮帮手 *******事务全攻略******
alter table tablename add id int identity(1,1)
saucer(思归, MS .NET MVP)的答案能解决我的问题,但第2次执行时会出现临时表已存在的提示,请问怎么解决? happydreamer(小黑-不懂的太多)可能没理解我的意图,我是想在查询出来的结果中出现1,2,3...的序号,如果用id类型的列的话,出来的不一定是从1开始的连续序号
select @i=@i+1,* from tablename
select (select count(*) from yourtable where id<=tem.id) as no,* from yourtable as tem
select identity(int,1,1) as 序号, * into #temp from yourtable
select * from #temp