I wanna create a table in SQL with the following 4 colums: id, year, month and day. But i wanna fill this colums automatically from the year of 2012 to 2020. What is the best way to do this? i googled but i couln't really find a solution. For example i want the table to show the following information.
ID year Month Day
1 2013 1 2
2 2013 1 3
3 2013 1 4
4 2013 1 5
4条答案
按热度按时间yiytaume1#
There is no need for loops, cursors or recursive CTEs... It's as easy as the following.
Or you can use it to populate a permanent table...
sz81bmfz2#
Using the VBoka suggestion, try this:
jtoj6r0c3#
Using CTE and no datetime functions:
vojdkbi04#