首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

sql 增多自增涨序号

2013-02-17 
sql 增加自增涨序号declare @strvarchar(2000)declare @i intset @i 1set @strSELECT @str@str+cast

sql 增加自增涨序号

declare @str  varchar(2000)
declare @i int
set @i = 1
set @str=''

SELECT @str=@str+cast((@i+1) as CHAR(1))+isnull(tm.sAnswer,'')
FROM tbAnswer t
left outer join dbo.tbPollMyAnswer tm on tm.iAnswerId=t.iAnswerId
WHERE t.iQuestionID=12 and tm.sAnswer is not null
print @str


如上
想加一个 序号,1,2,3,4......
大神们给点指点

[解决办法]
declare @str  varchar(2000)
declare @i int
set @i = 1
set @str=''
 
SELECT @str=@str+cast((@i+1) as CHAR(1))+isnull(tm.sAnswer,''),num=rownumber()over(order by getdate())
FROM tbAnswer t
left outer join dbo.tbPollMyAnswer tm on tm.iAnswerId=t.iAnswerId
WHERE t.iQuestionID=12 and tm.sAnswer is not null
print @str

[解决办法]
num=rownumber()over(order by getdate())

热点排行