datetime - Copying data with different dates in SQL Server -
i have table 4 columns , 8000 rows of data
datetime
column 2016-01-05. want copy these 8000 rows of data days of january 1st 31st.
meaning, should have 8000 * 31 days of data though same data.
how do without using excel document.
first, create temporary date table values each day in january 2016.
create table #tempdate (datecol datetime) declare @day int = 1 declare @date date = '2016-01-01' while @day <= 31 begin insert #tempdate values (@date) set @day +=1 set @date = dateadd(dd,1,@date) end
next, can select
desired columns , cross join
others have said well. should cartesian product between 2 tables (8000 x 31 rows).
select c.column1, c.column2, c.column3, t.datecol #tempdate t cross join yourtablename c
Comments
Post a Comment