I need to create a loop to pull records that are within a quarter from 2006 to the present. I have created a routine to increment the months and years using integers to get the begin and end dates for each quarter. I can't seem to use the integers to create a date.
DECLARE @EarnYear int,
@Beginer int,
@First int,
@QtrBegin datetime
SET @EarnYear = 2006
SET @Beginer = 1
SET @First 1
SELECT (CAST(CAST(@EarnYear as char(4)) +
right('00' + cast(@Beginer as varchar(2)),2) +
right('00' + cast(@First as varchar(2)),2) as datetime) as @QtrBegin
Can anyone help? Thanks.