I need to make a temporary table that holds of range of dates, as well as a couple of columns that hold placeholder values (0) for future use. The dates I need are the firs
Tested below and it works, though it's a bit convoluted.
I assigned arbitrary values to the dates for the test.
DECLARE @SD smalldatetime,
@ED smalldatetime,
@FD smalldatetime,
@LD smalldatetime,
@Mct int,
@currct int = 0
SET @SD = '1/15/2011'
SET @ED = '2/02/2012'
SET @FD = (DATEADD(dd, -1*(Datepart(dd, @SD)-1), @sd))
SET @LD = (DATEADD(dd, -1*(Datepart(dd, @ED)-1), @ED))
SET @Mct = DATEDIFF(mm, @FD, @LD)
CREATE TABLE #MyTempTable (FoM smalldatetime, Trials int, Sales money)
WHILE @currct <= @Mct
BEGIN
INSERT INTO #MyTempTable (FoM, Trials, Sales)
VALUES
(DATEADD(MM, @currct, @FD), 0, 0)
SET @currct = @currct + 1
END
SELECT * FROM #MyTempTable
DROP TABLE #MyTempTable