Question

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
Was it helpful?

Solution

Select  '[' + cast(row_number() OVER (order by Name) as varchar(100))  + ']' + Name From People
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top