Hello in the code below I am manually plugging in the year
to insert 12 months of data into a table.
I would like to increment the year by 1 each time 12 months of data is inserted until I get to 2011. Not quite sure how to do this. Thank you for reading and taking time
DECLARE @MoveInYear varchar(10)
DECLARE @MoveInMonthNumber int
SET @MoveInYear = '1997'
SET @MoveInMonthNumber = 1
WHILE @MoveInMonthNumber < 13
BEGIN
INSERT INTO DailyAdmits
SELECT COUNT(Offender_Number)Admitted , MoveInDay, MoveInMonth,MoveInYear,MoveInDayName
FROM Housing
WHERE [MoveInYear]=@MoveInYear
AND MICLASS='LODGE'
AND [MoveInMonthNumber]=@MoveInMonthNumber
GROUP BY MoveInDay,MoveInMonth,MoveInYear,MoveInDayName
ORDER BY MoveinDay
SET @MoveInMonthNumber = @MoveInMonthNumber + 1
END
to insert 12 months of data into a table.
I would like to increment the year by 1 each time 12 months of data is inserted until I get to 2011. Not quite sure how to do this. Thank you for reading and taking time
DECLARE @MoveInYear varchar(10)
DECLARE @MoveInMonthNumber int
SET @MoveInYear = '1997'
SET @MoveInMonthNumber = 1
WHILE @MoveInMonthNumber < 13
BEGIN
INSERT INTO DailyAdmits
SELECT COUNT(Offender_Number)Admitted , MoveInDay, MoveInMonth,MoveInYear,MoveInDayName
FROM Housing
WHERE [MoveInYear]=@MoveInYear
AND MICLASS='LODGE'
AND [MoveInMonthNumber]=@MoveInMonthNumber
GROUP BY MoveInDay,MoveInMonth,MoveInYear,MoveInDayName
ORDER BY MoveinDay
SET @MoveInMonthNumber = @MoveInMonthNumber + 1
END