当前位置: 代码迷 >> Sql Server >> 大家新年好!请问一个自定义函数的有关问题
  详细解决方案

大家新年好!请问一个自定义函数的有关问题

热度:73   发布时间:2016-04-24 09:20:19.0
大家新年好!请教一个自定义函数的问题


with a (x) as
(select 101 union all
 select x+1 from a where x<200
)
select ROW_NUMBER() over (order by x) as id,* from a 

--在Server 2000 中能通过自定义函数生成一个排序列吗?
--用indetity要配合INTO 使用,
--Server 2000 不支持ROW_NUMBER(),我需要在查询语句中使用。

/*
id                   x
-------------------- -----------
1                    101
2                    102
3                    103
4                    104
5                    105
6                    106
....
*/
------解决思路----------------------
with a (x) as
(select 101 union all
 select x+1 from a where x<200
)



select (select count(1) AS ID FROM a as b where a.x>=b.X) as id,x from a
  相关解决方案