I also have the date which fetches the previous one month worth of data.
For ex:
Today’s date is Feb-27-2012, and if i want to fetch the previous one month of data, then this WHERE clause works fine.
year(TABLE_NAME.EFF_END_DT) = year(sysdate()) and
month(TABLE_NAME.EFF_END_DT) = month( sysdate()) -1
But here comes the trouble,
I want to fetch a year’s worth of data
And if i am running my job on 5th of Jan 2012, and i want the previous one year worth of data or one month of data, then this WHERE clause does not work.
Ex: If i execute my job on Jan 5th 2012, and i want to fetch one month of previous data i.e Dec 1 to Dec 31 2011, then how would i use the condition in my WHERE clause.
Can anyone pls suggest me some idea.
Previous one month of data from the current sysdate()
Previous one year worth of data from the current sysdate()
1.Get the sysdate using a global variable
2.For your start date use addmonths function to get the previous month and subtract that
value with dayinmonth function to get previous month start value.
3.For end date = get the day in month using the function and subtract with sysdate, this gives last date for previous month.
4. Use the start and end date global variables in your where clause.
The script I provided is for previous month load based on sysdate. The where clause you use is different. Thats why the counts don’t match.
You want to run previous month timeframe based on sysdate rite?
Try running the date range you pass in dataservices against database and see if the counts are same.
Ok,
Here’s the catch.
I am using your script in the script editor, and joining it to the DF.
In the DF (WHERE clause), i have nothing.
When i run the job, i see that i am extracting the data from
1999-01-01 00:00:00.000.
So. the script that i am adding before the DF is not doing its job or just fetching one months OR one year’s worth of data.
9072 7688 PRINTFN 2/27/2012 11:12:16 AM CURRENT DATE = '2012.02.27'
9072 7688 PRINTFN 2/27/2012 11:12:16 AM START DATE = '2012.01.01'
9072 7688 PRINTFN 2/27/2012 11:12:16 AM END DATE = '2012.01.31'
I ask again the same question. Should this script be added in the WHERE clause in the DF or in the script editor and join it to the DF?
[Query:Join_Query]
Invalid WHERE clause. Additional information: <Syntax error at line <15>: <(DWSE_AFFILIATIONS.EFF_END_DT('01' || to_char(add_months( sys>: near <(> found <'('> expecting <')', ALL, CONVERT, DOUBLE, FILE, GENERATED, HAVING, INPUT, an integer, LEFTOUTERJOIN, LOAD, __AL_MESSAGE, *, <>, NFIXCHAR, SYSTEM, char 425>.
1 error(s), 0 warning(s).
Check and fix the syntax and retry the operation. (BODI-1112394)>. (BODI-1111078)
Not able to get the right script to fetch the previous months/year of data
I have a job that run’s on every 5th of the month, and what i need is the data one month back.
Ex: I executed a job for our testing purpose, just now (Feb 28-2012).
If i run the job, it should take the data from Mar 27-2012 to Feb 27-2012)
But this is what i am getting
2011-02-14 00:00:00.000
2012-01-31 00:00:00.000
How do i tweek this script so that it will fetch the data from today’s date to one year back…
I have the similar requirement, however I need to calculate exact 3 month back start date from the current date and not month, is it possible to get that ?
For example if today is 03.12.2019 and I am using the above code for start and end date it is giving me
START_DATE = 01.09.2019
END_DATE = 30.11.2019 (replaced 1 with 3 in the END_DATE calculation)
instead I want it to be
START_DATE = 02.09.2019
END_DATE =02. 12.2019
Hope it is clear. Thanks for your help in advance.