How to create table with a column computed by another table in SQL Server?
For example:
TableA:
Name SerialNoStart SerialNoEnd
A 1 3
B 2 4
C 1 1
I want create a new table with serial number between SerialNoEnd and SerialNoStart
The new table as following:
TableB:
Name SerialNo
A 1
A 2
A 3
B 2
B 3
B 4
C 1
How to make it? Thanks!
You can split the data out using a recursive CTE, similar to this:
See SQL Fiddle with Demo