将Row_Number列与其他列合并

时间:2014-04-22 08:33:25

标签: sql sql-server merge row-number

我有一个名为People的表格,其中包含两列Name& Age。我想编写一个查询,它将检索Name列,并将row_number合并到每一行。这样的事情: -

       Name
-------------------
[ROW_NUMBER] Stan
[ROW_NUMBER] Alex
[ROW_NUMBER] Steven

行号为1,2,3,同时添加括号。

这就是我试过的

Select ( '[' + row_number() OVER (order by Name) + ']' + Name) From People

1 个答案:

答案 0 :(得分:1)

Select  '[' + cast(row_number() OVER (order by Name) as varchar(100))  + ']' + Name From People