sql 增加自增涨序号

anlianganl 2013-01-29 11:45:32
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......
大神们给点指点
...全文
200 3 点赞 打赏 收藏 举报
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
-Tracy-McGrady- 2013-01-29
num=rownumber()over(order by getdate())
  • 打赏
  • 举报
回复
Mr_Nice 2013-01-29
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
  • 打赏
  • 举报
回复
kingtiy 2013-01-29

DECLARE @str VARCHAR(2000)
DECLARE @i INT
SET @i = 1
SET @str = ''
 
SELECT  @str = @str+ ROW_NUMBER()OVER(ORDER BY tm.sAnswer ) AS RID, + 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
  • 打赏
  • 举报
回复
相关推荐
发帖
疑难问题
加入

2.1w+

社区成员

MS-SQL Server 疑难问题
申请成为版主
帖子事件
创建了帖子
2013-01-29 11:45
社区公告
暂无公告