Repository Query Language select data between data range - atg

I'm beginner of RQl and I have a product table which have end date for all the products. Now I want to retrieve all products who's end date is null within given time period.
I tried below.
endDate IS NULL BETWEEN ?1 AND ?2;
But it's not work. Can anyone help me.

Related

Power Query - Subtract the earliest date in one column from the record-specific date in another column

Every month I download a set of data into a report. That data consists of multiple records and each record has a record specific date as well as having the month end report date on the record's data-row.
I have used Power Query to upload all of these month end reports. I want use Power Query to be able to compare the column of record dates with the earliest date in the column of report dates to see if anybody has fiddled any data entry. The query table has the following headings.
Record ID Record Date Report Date
I've tried adding a custom column using the formula = if Record Date < List.Min(Report Date) then "Old" else "New"
this didn't work and I've spent ages trying to get a solution. I've also tried using Groups to get the minimum value, but I lose all of the other columns, which I want to keep. Any help really appreciated.
You have to refer to the fields in [], so here [Report Date]
To pick a column use Source[Field], so here #"PriorStep"[Report Date]
The List.Min function is not pulling as a number so you cant use <
Insert a Number.From in front of the calculation to convert to number
Same need to add Number.From in front of [Record Date] pulling as a date
Combined code:
#"Added Custom" = Table.AddColumn(#"PriorStep", "Custom", each if Number.From([Record Date])<Number.From(List.Min(#"PriorStep"[Report Date])) then "Old" else "New")

Cast varchar as date select distinct top 100

I am trying to fix a query that has come to light in SSRS after the new year. We have an input that comes from another application. It grabs a date and stores it as varchar. The SSRS report then fetches the top 100 'dates' but when 2017 dates have come around, this are not in the top 100.
The existing query is as follows
SELECT DISTINCT TOP (100)
FROM DenverTempData
ORDER by BY Date DESC
The date is stored as VARCHAR. So obviously this query doesn't grab a value such as 01012017 as being a top 100 (over values likes 12312016). I thought maybe I can simply change the datatype on this column to datetime. But the information comes from a flat file and is converted, so it's a little more difficult that that. So I'm hoping to do a select of the distinct top 100 while converting the date column to datetime or just date and grabbing the last 100 dates.
Can someone help with the query syntax? I'm thinking a cast to convert varchar to date, but how do I format with distinct top 100? I'm simply looking to retrieve the last 100 dates in chronological order from a column that is stored as varchar but contains a string representing a date.
Hopefully that makes sense
It is always a bad idea to store a date as string. This is highly culture specific!
You can cast your formatted string-date to a real date like this:
DECLARE #DateMMDDYYYY VARCHAR(100)='12312016';
SELECT CONVERT(DATE,STUFF(STUFF(#DateMMDDYYYY,5,0,'-'),3,0,'-'),110)
After the conversion your sorting (and therefore the TOP 100) should work as expected.
My strong advise: Try to store your dates in a column of a real date type to avoid such hassel!
SELECT DISTINCT TOP 100 (CAST(VarcharColumn as Date) as DateColumn)
FROM TABLE
Order by DateColumn desc

SQL query to find date between a range of dates

Table X has start_date and end_date and related information associated with these dates. BOTH stored in DB in date format.
I need to find a specific date say 12th-Jan-2000 and extract the rows whose date range includes this date.
Could someone please help me out. I am new to SQL so need some guidance here.
Table X:
ID |start_date|end_date
1 |12/30/1999|01/12/2000
2 |01/20/2000|01/30/2000
3 |01/07/2000|01/15/2000
Thus my query should give back the ID-3 since 12th January falls in the range 01/07/2000-01/15/2000
Thanks
use the BETWEEN operator:
SELECT *
FROM TableX
WHERE DATE'2000-01-12' BETWEEN start_date AND end_date

Mass delete records from custom object via apex class

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

Need to add a Column to signify Active or Termed Status

I am creating a table that has a variety of Employee data in fields. I need to add a column that will display an "Active" or "Termed" status based weather there is a date in the Termination Date column.
For example, If the employee has a date in the StartDate column but not in the EndDate column then the EmpStatus Column will return an "Active" status. If there is a date in the EndDate column then it will return a "Termed" Status.
I am loading a master table from a view is the fastest and easiest way to do it.
The question is, where can I find a script that will perform the function I need.
SELECT CASE WHEN EndDate is not null then 'Termed'
WHEN StartDate is not null then 'Active'
else 'unknown' end as EmpStatus
FROM employee