Skip to content
Advertisement

T-SQL – adding more date values to a table all rows

I have a table that contains many IDs as random numbers and I would like to create another table that contains all the IDs with another column having dates from first day of the year until a specific date.

For example: My actual table looks like:

And I would like to have a table if my specific end date is 2020-01-03 that looks like:

Could you help me to solve my issue? Thanks in advance!

Advertisement

Answer

You can use a recursive CTE to define the dates and then cross join:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement