SET NOCOUNT ON;
--DECLARE @date_code integer;
DECLARE @start_date datetime;
DECLARE @end_date datetime

--SETVAR date_code 1;

IF $(date_code) = 2
BEGIN
  -- test date range
  SET @start_date = '20090101';
  SET @end_date = '20200101';
END
ELSE
IF $(date_code) = 3
BEGIN
  -- test date range for rows
  SET @start_date = '20110801';
  SET @end_date = '20111101';
END
ELSE
--IF $(date_code) = 1
BEGIN
  -- month date range
  -- set start_date to beginning of previous month
  SET @start_date = DATEADD(mm,(YEAR(CURRENT_TIMESTAMP)-1900)* 12 + MONTH(CURRENT_TIMESTAMP) - 2, 0);
  -- set end_date to start_date plus 1 month
  SET @end_date = DATEADD(mm,1,@start_date) ;
END
