I wish to define a start and end date for my SQL query in Netezza.
My code is re-run every quarter to pull the latest data and rather than changing the date fields in multiple locations in the code I wish to define a start and end date that can be re-used throughout the code.
I have been trying the following code to get the start and end date in Aginity but my code will not run
CREATE OR REPLACE PROCEDURE START_END_DATE_VARS()
--SPECIFIC START_END_DATE_VARS
LANGUAGE NZPLSQL
BEGIN
declare StartDate char;
declare EndDate char;
SELECT StartDate = TO_CHAR(last_day(add_months(now(),-1)),'YYYY-MM-DD') INTO StartDate;
SELECT EndDate = TO_CHAR(add_months(date_trunc('month', current_date),-35),'YYYY-MM-DD') INTO EndDate;
END
I would be very grateful if you could give me a steer in the right direction as to how to define these variables in Aginity/Netezza.