Create Table T(stcd varchar(10),name varchar(10))
insert into T select 's001','A'
union all select 's002','B'
union all select 's003','C'
union all select 's004','D'
--建视图
Create View VIEW_T
as
select * from T
--查询
select autoid=(select sum(1) from VIEW_T where stcd<=A.stcd),*
from VIEW_T A
--结果
序号 stcd name
----------- ---------- ----------
1 s001 A
2 s002 B
3 s003 C
4 s004 D
Drop Table T
Drop View VIEW_T