SELECT (SELECT COUNT(*) FROM TABLE WHERE stuname<=A.stuname) AS XH,stuname FROM TABLE A
tj_dns(愉快的登山者) 的方法是可行的,你是不是在具体使用时 没作好。简单说明一下:select identity(int,1,1) xh, * into #temp from table /*该语句将表table的全部数据放到局部临时表#temp中,并在临时表生成自动 加1的字段xh。如需要全局临时表,将#temp改为##temp即可*/select * from #temp /*该语句从上文生成的临时表中提取你所需要的数据*/
那如果我真正在ASP上用的时候,总不能这样子来访问这个局部临时表#temp吧!!
表里没这个字段,加上就可以了.--在表中添加此字段 alter table 表名 add xh int identity(1,1)如果你只是在查询时生成,就用临时表: select xh=identity(int,1,1),stuname into #tb from table select * from #tb drop table #tb
ASP上我不是很清楚,如果是当前连接,应该可以,你测试一下。
可以在ASP中用个变量来实现这个自动加1功能,先让变量初始为1,然后让它随表的记录数自动增加即可。
表里没这个字段,加上就可以了.--在表中添加此字段 alter table 表名 add xh int identity(1,1)如果你只是在查询时生成,就用临时表: create table #tb(xh,int identity(1,1),stuname) go select xh=identity(int,1,1),stuname into #tb from table select * from #tb drop table #tb
FROM TABLE A
没作好。简单说明一下:select identity(int,1,1) xh, * into #temp from table
/*该语句将表table的全部数据放到局部临时表#temp中,并在临时表生成自动
加1的字段xh。如需要全局临时表,将#temp改为##temp即可*/select * from #temp
/*该语句从上文生成的临时表中提取你所需要的数据*/
alter table 表名 add xh int identity(1,1)如果你只是在查询时生成,就用临时表:
select xh=identity(int,1,1),stuname into #tb from table
select * from #tb
drop table #tb
alter table 表名 add xh int identity(1,1)如果你只是在查询时生成,就用临时表:
create table #tb(xh,int identity(1,1),stuname)
go
select xh=identity(int,1,1),stuname into #tb from table
select * from #tb
drop table #tb