none
SQL loop

    Question

  • I have last two years data 2017 and 2018. i was using loops to run autmation data reports. but now year has been changed and I'm unable to get 2018 data as current period is 2019 and prior period is 2017.

    i can can not use hard code values in procedures. any help to get 2018 (by month) as current period.

    SET  @= ( SELECT TRIM(EXTRACT(YEAR FROM CURRENT_DATE) - 2 || '-12-01')); ---------as 2017 data
    SET @ = (SELECT CAST(TRIM(EXTRACT(YEAR FROM CURRENT_DATE) - 2 || '-12-01') AS INT));-----as 2017
    SET @ = (SELECT CURRENT_DATE  ); -------2019 
    SET @ = (SELECT CAST(CAST((CURRENT_DATE (FORMAT 'YYYYMMDD') ) AS CHAR(8)) AS INT)); ------2019 but want pull 2018 data list
    SET @= (SELECT CAST(CAST((ADD_MONTHS(EXTRACT(YEAR FROM CURRENT_DATE) - 1 || '-12-01', 0) (FORMAT 'YYYYMMDD')) AS CHAR(8)) AS INT));

    • Edited by R00Tt Friday, January 11, 2019 2:42 AM
    Friday, January 11, 2019 2:34 AM

All replies