I am trying to make SET variables in SnowSQL that will specify the first of each start month and end month for the current year and previous years respectively. I want the code to be able to roll over to the new month as time progresses. So for example, since it is June 2020 we would have m2_start = 2020-06-01 and m2_end = 2020-07-01. m1_start = 2019-06-01 and m1_end 2019-07-01. Here is what I have so far, but it is not quiet what I want as I can't figure out how to specify on the first of the month:
SET m1_start = (SELECT DISTINCT DATEADD(year,-1,CURRENT_DATE) FROM DIMDATE d WHERE DAY(d."Date") = 1);
SET m1_end = (SELECT DISTINCT DATEADD(month, -11,CURRENT_DATE) FROM DIMDATE d WHERE DAY(d."Date") = 1);
SET m2_start = (SELECT d."Date" FROM DIMDATE d WHERE DAY(d."Date") = 1 AND MONTH(d."Date") = MONTH(CURRENT_DATE) AND YEAR(d."Date") = YEAR(CURRENT_DATE));
SET m2_end = (SELECT DISTINCT DATEADD(month, 1,CURRENT_DATE) FROM DIMDATE d WHERE DAY(d."Date") = 1);
SET Test = '2020-06-01';