当前位置: 代码迷 >> Sql Server >> 根据一列的值,生成自增ID的有关问题
  详细解决方案

根据一列的值,生成自增ID的有关问题

热度:179   发布时间:2016-04-27 21:49:59.0
根据一列的值,生成自增ID的问题
如下:
name     id
ass       1
ass       2
ass       3
rty       1
qwe       1
qwe       2  
qwe       3
qwe       4
想这样,令ID列为自增ID,根据NAME列的值自增,这样的表怎么创建啊????

------解决方案--------------------
-- 上边的函数有点问题.这个就对了.

alter function dbo.fn_testid
(@name varchar(20))
returns int
as
begin
declare @count int
select @count=isnull(count(*),0)+1 from test
where [name][email protected]
return(@count)
end
Go
------解决方案--------------------
SQL2005有dense_rank函数,刚好就是楼主的要求了,呵呵
  相关解决方案