Mass delete records from custom object via apex class - triggers

Aim- I want to delete any record within custom object training__c where the created date is greater than 6 months from today's date.
I would like to run this job daily.
I apologise if the following below has errors I just wrote this on my iPhone, Does the following logic below make sense ?
Looking forward to your help
List listsObject = [Select Id from training where Createddate <= ( Current Date - 6 months)
Limit 9000];Delete

Yo can select by using Date Literals such as LAST_N_DAYS
e.g.
List listsObject = [Select Id from training where CreatedDate <= LAST_N_DAYS:180];
delete listsObject;
More about Date Literals

Related

How to get data according to a user defined date in Tableau?

I am creating a tableau dashboard and it should load data according to the date the user enters. This is the logic that I am trying.
select distinct XX.ACCOUNT_NUM, (A.TOTAL_BILLED_TOT-A.TOTAL_PAID_TOT)/1000 arrears, ((A.TOTAL_BILLED_TOT-A.TOTAL_PAID_TOT)/1000 - XX.SUM_BILL ) TILL_REF_JUL20
FROM
(
select /*+ parallel (bill ,40 ) */ distinct account_num, sum(INVOICE_NET_mny + INVOICE_TAX_mny)/1000 SUM_BILL
from bill
where account_num in (Select account_num from MyTable)
and trunc(bill_dtm) > ('07-Aug-2021') –-Refmonth+1 month and 07 is a constant. Only month and year is changing
and cancellation_dtm is null
group by account_num
)xx , account a
where xx.ACCOUNT_NUM = A.account_num
Here is what I tried. First created a parameter called ref_Month. Then created a calculated field with this.
[Ref_Month]=MAKEDATE(DATETRUNC('year',(DATEADD('month', 1, [Ref_Month])), 07))
But I am getting an error. I am using a live connection. Is there any method to achive this?
I don't understand what this statement is trying to do:
[Ref_Month]=MAKEDATE(DATETRUNC('year',(DATEADD('month', 1, [Ref_Month])), 07))
If Ref_Month is a date, which it has to be for DATEADD to be a valid operation, why not make it the 7th of whatever starting month and year you are starting with? Then DATEADD('month',1, [Ref_Month]) will be a month later, still on the 7th. So you don't need DATETRUNC or MAKEDATE at all.
That said, how, when, and where are you trying to COMPUTE a PARAMETER,
let alone based on itself?

Azure Data Factory - Date Expression in component 'derived column' for last 7 Days

I am very new to Azure Data Factory. I have created a simple Pipeline using the same source and target table. The pipeline is supposed to take the date column from the source table, apply an expression to the column date (datatype date as shown in the schema below) in the source table, and it is supposed to either load 1 if the date is within the last 7 days or 0 otherwise in the column last_7_days (as in schema).
The schema for both source and target tables look like this:
Now, I am facing a challenge to write an expression in the component DerivedColumn. I have managed to find out the date which is 7 days ago with the expression: .
In summary, the idea is to load last_7_days column in target Table with value '1' if date >= current date - interval 7 day and date <= current date like in SQL.I would be very grateful, if anyone could help me with any tips and suggestions. If you require further information, please let me know.
Just for more information: source/target table column date is static with 10 years of date from 2020 till 2030 in yyyy-mm-dd format. ETL should run everyday and only put value 1 to the last 7 days: column last_7_days looking back from current date. Other entries must recieve value 0.
You currently use the expression bellow:
case ( date == currentDate(),1, date >= subDays(currentDate(),7),1, date <subDays(currentDate(),7,0, date > currentDate(),0)
If we were you, we will also choose case() function to build the expression.
About you question in comment, I'm afraid no, there isn't an another elegant way for. To achieve our request, Data Flow expression can be complex. It may be comprised with many functions. case() function is the best one for you.
It's very clear and easy to understand.

Quicksight datepicker for month only

I'm searching for a way to have month selection and that will serve as startdate and enddate for the date filtering.
I'm building a monthly report on quicksight, I try to use the last 31 days but that give information of multiple months
I already create date picker for those parameters but didn't find any way to limit the value to be the complete month only.
Example : if select the 12 september I desire to get the September values only (from the 1er to the 31th)
Any advice is welcome
Thanks for your help
First, add a new date filter (if you want, e.g., today to be the default you'll need to add a dynamic default against a data set that returns today)
Add a new control (I found naming this to be difficult, perhaps you're better at picking names than I am)
Add a new calculated field that returns 1 if the truncDate of your date field and the truncDate of your parameter are equal, otherwise return 0
ifelse(
truncDate("MM", {date}) = truncDate("MM", ${InMonth}),
1,
0
)
Finally, add a filter that checks where your calculated field is 1 and apply it to all visuals

Managing dates in SPSS - Time difference in months

Im a novice SPSS user and are working on a data set with two columns, customer ID and order date. I want to create a third variable with a month integer of number of inactive months since the observed customer ID:s last order date. This is how the data looks like:
This will create some sample data to demonstrate on:
data list list/ID (f3) OrderDate (adate10).
begin data
1 09/18/2016
1 03/02/2017
1 05/12/2017
2 06/06/2016
2 09/09/2017
end data.
Now you can run the following syntax to create a variable that contains the number of complete months between the date in the present row and the date in the previous row:
sort cases by ID OrderDate.
if ID=lag(ID) MonthSince=DATEDIF(OrderDate, lag(OrderDate), "months").

Newbie to HQL - Date conversions in Hive - extract Year from free flow text varchar100

I have a simple HQL statement which works. I want to be able to count the occurrence's by Year or by Month. The data Quality is not good,and the incorporationdate column is held as a varchar100 and contains free flowing text and nulls
So I cannot use Substring or YEAR as I need to only perform a extract on the format mm/dd/yyyy to pull out the Year or month. Ideally I would like to create a View and create 2 new Columns , one to show the year and one to show the month this would be the perfect scenario.
select
incorporationdate, count(incorporationdate) from default.chjp2
group by companynumber,incorporationdate
===================================================
Regards
JP
you could use if and test any condition you want before using substring:
select if(date is not null and date rlike '^\d{2}\/\d{2}\/\d{4}$', substr(7),null)