In SQL Server how can I add a ordinal/identity/row number to this result set?
select *
from (VALUES('c'), ('a'), ('b')) t(value)
value |
---|
c |
a |
b |
So it returns the same as this:
select *
from STRING_SPLIT('c,a,b', ',', 1) t
value | ordinal |
---|---|
c | 1 |
a | 2 |
b | 3 |
I don't want to just do VALUES(1,'c'),(2,'a'),(3,'b')
because there will be a long list that will change from time to time and can't have gaps in the ordinal.
1条答案
按热度按时间g6ll5ycj1#
You can't do it using the
values
constructor, the closest you can get is to use a table variable with an identity column e.g.Returns