Bashar Al-Khalili
Bashar Al-Khalili

Reputation: 31

Merging Row_Number column with other column

I have a table called People that has two columns, Name & Age. I'd like to write a query that will retrieve the Name column with the row_number merged into each row. something like this : -

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

Row number being 1,2,3, Whilst adding the brackets as well.

This is what I tried

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

Upvotes: 1

Views: 191

Answers (1)

Habeeb
Habeeb

Reputation: 1040

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

Upvotes: 1

Related Questions