Reputation: 2708
I am trying to execute a series of selects in a statement in sql server with a union between them. Now I want in a select statement to include a variable from the t-sql code and increment it with each new entry. How can I do this?
Upvotes: 0
Views: 84
Reputation: 13700
You can use ROW_NUMBER() function instead of a variable
select row_number() over (order by keycol) as row_num, * from
(
Your UNION queries here
) as t
Upvotes: 1