Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
phrankbooth
Posting Yak Master
162 Posts |
Posted - 2013-10-11 : 16:42:54
|
I want to generate 356 rows, representing each day, for each row in a second table. Like this:Table1:Fld1|Fld2|Fld3A|B|CD|E|FResult:A|B|C|07|01|2013A|B|C|07|02|2013A|B|C|07|03|2013...A|B|C|06|30|2014...D|E|F|07|01|2013D|E|F|07|02|2013D|E|F|07|03|2013...D|E|F|06|30|2014What's the best way to do this?Thanks!--PhB |
|
phrankbooth
Posting Yak Master
162 Posts |
Posted - 2013-10-11 : 17:01:41
|
I figured it out with a CTE and cross join. DECLARE @Amount float = .025 ;With DateSequence( [Date], Amount ) as ( Select @CurrentFYBeginDate as [Date], @Amount Amount union all Select dateadd(Day, 1, [Date]), @Amount Amount from DateSequence where Date < @CurrentFYEndDate ) Select * from DateSequence cross join ( SELECT Fld1, Fld2,Fld3 FROM Table1 ) X OPTION (MAXRECURSION 32767)--PhB |
|
|
|
|
|