Hi,
I have a SOQL problem and am hoping it can be solved here on the SQL forum
I have a bunch of queries that need to run on the 1st of every month, and I use the function "GetDate()". If for some reason I need to re-run these queries and it's not the 1st of the month, I have to Hard-code the date. per the two examples below.
1st of Month run:
AND WARRANTY_START_DATE between DATEADD(MONTH,-9,cast(GetDate() as date)) and DATEADD(MONTH,-8,cast(GetDate() as date))
Not first of month:
AND WARRANTY_START_DATE between DATEADD(MONTH,-9,cast('2022-11-01' as date)) and DATEADD(MONTH,-8,cast('2022-11-01' as date))
My issue is that there are a lot of these and having to update the date in each seems like waisted time.
I'd like to 'look' into another table (data extension) and find the date there. So I'll have a new table with 1 column/value. Table: Report_Month, Column: Date = '2022-11-01'. This will be changed monthly.
Update my queries to look at that table to find the date, replacing my "GETDATE()' or Hard-coded date:
Something like:
AND WARRANTY_START_DATE between DATEADD(MONTH,-9,cast(Report_Month.Date as date)) and DATEADD(MONTH,-8,cast(Report_Month.Date as date))
Ideas of how I'd accomplish this? SOQL, not SQL.
Thanks.