Rally API date filter doesn't work - rally

I am trying to filter the data based on date but it fetch all
The format of "FlowStateChangedDate": "2018-07-18T01:00:15.301Z",
https://host.com/slm/webservice/v2.0/hierarchicalrequirement?query
=((FlowStateChangedDate >= 2018-06-01 ) AND (FlowStateChangedDate <= 2018-06-02) )&fetch=FormattedID&start=1&pagesize=2000

The url should be encoded.Else at least
>= should be %3E%3D
<= should be %3C%3D

Related

Retrieve data 60 days prior to their retest date

I have a requirement where I need to retrieve Row(s) 60 days prior to their "Retest Date" which is a column present in the table. I have also attached the screenshot and the field "Retest Date" is highlighted.
reagentlotid
reagentlotdesc
u_retest
RL-0000004
NULL
2021-09-30 17:00:00.00
RL-0000005
NULL
2021-09-29 04:21:00.00
RL-0000006
NULL
2021-09-29 04:22:00.00
RL-0000007
Y-T4
2021-08-28 05:56:00.00
RL-0000008
NULL
2021-09-30 05:56:00.00
RL-0000009
NULL
2021-09-28 04:23:00.00
This is what I was trying to do in SQL Server:
select r.reagentlotid, r.reagentlotdesc, r.u_retestdt
from reagentlot r
where u_retestdt = DATEADD(DD,60,GETDATE());
But, it didn't work. The above query returning 0 rows.
Could please someone help me with this query?
Use a range, if you want all data from the day 60 days hence:
select r.reagentlotid, r.reagentlotdesc, r.u_retestdt
from reagentlot r
where
u_retestdt >= CAST(DATEADD(DD,60,GETDATE())
AS DATE) AND
u_retestdt < CAST(DATEADD(DD,61,GETDATE()) AS DATE)
Dates are like numbers; the time is like a decimal part. 12:00:00 is half way through a day so it's like x.5 - SQLServer even lets you manipulate datetime types by adding fractions of days etc (adding 0.5 is adding 12h)
If you had a column of numbers like 1.1, 1.5. 2.4 and you want all the one-point-somethings you can't get any of them by saying score = 1; you say score >= 1 and score < 2
Generally, you should try to avoid manipulating table data in a query's WHERE clause because it usually makes indexes unusable: if you want "all numbers between 1 and 2", use a range; don't chop the decimal off the table data in order to compare it to 1. Same with dates; don't chop the time off - use a range:
--yes
WHERE score >= 1 and score < 2
--no
WHERE CAST(score as INTEGER) = 1
--yes
WHERE birthdatetime >= '1970-01-01' and birthdatetime < '1970-01-02'
--no
WHERE CAST(birthdatetime as DATE) = '1970-01-01'
Note that I am using a CAST to cut the time off in my recommendation to you, but that's to establish a pair of constants of "midnight on the day 60 days in the future" and "midnight on 61 days in the future" that will be used in the range check.
Follow the rule of thumb of "avoid calling functions on columns in a where clause" and generally, you'll be fine :)
Try something like this. -60 days may be the current or previous year. HTH
;with doy1 as (
select DATENAME(dayofyear, dateadd(day,-60,GetDate())) as doy
)
, doy2 as (
select case when doy > 0 then doy
when doy < 0 then 365 - doy end as doy
, case when doy > 0 then year(getdate())
when doy < 0 then year(getdate())-1 end as yr
from doy1
)
select r.reagentlotid
, r.reagentlotdesc
, cast(r.u_retestdt as date) as u_retestdt
from reagentlot r
inner join doy2 d on DATENAME(dayofyear, r.u_retestdt) = d.doy
where DATENAME(dayofyear, r.u_retestdt) = doy
and year(r.u_retestdt) = d.yr

Hive query to return single row based on eff and exp date

I have a table with the following data.
I am expecting row which needs to be returned is with exp_dt "2020-09-22". But when run below query it returning both the rows. I am not understanding why it is returning the first row also when it has eff_dt "2020-09-19".
select id,cd,eff_dt,exp_dt,post_dt from table
where from_unixtime(unix_timestamp(eff_dt,"yyyy-MM-dd")) <= from_unixtime(unix_timestamp("2020-09-21","yyyy-MM-dd"))
and from_unixtime(unix_timestamp(exp_dt,"yyyy-MM-dd")) >= from_unixtime(unix_timestamp("2020-09-21","yyyy-MM-dd"));
Is there any issue with my query? I am expecting 2nd row to be returned.
Use < for the comparison to exp_date:
select id,cd,eff_dt,exp_dt,post_dt
from table
where from_unixtime(unix_timestamp('2020-09-21', 'yyyy-MM-dd')) >= from_unixtime(unix_timestamp(eff_dt, 'yyyy-MM-dd')) and
from_unixtime(unix_timestamp('2020-09-22', 'yyyy-MM-dd')) < from_unixtime(unix_timestamp(exp_dt, 'yyyy-MM-dd'))
I reversed the comparison order. I find it easier to follow the logic with the constants first.
Does this capture the edge case of equal same day expiry and solve your problem at the same time?
select id,cd,eff_dt,exp_dt,post_dt from table
where
(from_unixtime(unix_timestamp(eff_dt,"yyyy-MM-dd")) <= from_unixtime(unix_timestamp("2020-09-21","yyyy-MM-dd"))
and
from_unixtime(unix_timestamp(exp_dt,"yyyy-MM-dd")) > from_unixtime(unix_timestamp("2020-09-21","yyyy-MM-dd"))
)
or
(from_unixtime(unix_timestamp(eff_dt,"yyyy-MM-dd")) = from_unixtime(unix_timestamp("2020-09-21","yyyy-MM-dd"))
and
from_unixtime(unix_timestamp(exp_dt,"yyyy-MM-dd")) = from_unixtime(unix_timestamp("2020-09-21","yyyy-MM-dd"))
)
;
In fact I suspect exp is always >= eff, so maybe only one condition
from_unixtime(unix_timestamp(eff_dt,"yyyy-MM-dd")) <= from_unixtime(unix_timestamp("2020-09-21","yyyy-MM-dd"))
is enough...?
You do not need from_unixtime(unix_timestamp()) because dates are already in correct format and argument is in the same yyyy-MM-dd format.
The issue in your query is that you are using equal for both eff and exp dates
To find latest record on date use this query:
select id,cd,eff_dt,exp_dt,post_dt from table
where eff_dt <= "2020-09-21"
and exp_dt > "2020-09-21";
There should be no records when eff_dt = exp_dt in SCD2 if you have only date (without time component). dates can be equal only if you are using timestamps, and time is different, in this case convert your argument date to timestamp before checking.
SCD2 should be designed in such way that fact record can be mapped to exactly one record of SCD2.

Create a timestamp range between two different columns

I am trying to create a query and in the where clause I want to have a timestamp range between two different timestamp columns(starttime & endtime). I tried this but it fetched 0 results:
select *
from db.db_users
where ('<user_start_date>' >= starttime and '<user_end_date>' <= endtime)
and username ilike '%thodoris%'
limit 5;
user_start_date & user_end_date supposed to be user's values and different between them:
e.g.(2020-07-10 00:00:00 & 2020-07-10 23:59:59).
I want to ask if there is any other way to do this.
First, you should be using parameters. Second, the logic for a complete overlap is:
where start_date < :user_start_date and
end_date > :user_end_date
And for a partial overlap:
where start_date < :user_send_date and
end_date > :user_start_date

SQL Query to fetch data between minutes and days

I have requirement, this is for a report.
Requirement description:
Need data from a table which are in OPEN status for more than 30 minutes
Well, the above requirement can be obtained from
select *
from xyz
where status = 'OPEN'
and last_update_date <= sysdate - (30/1440) --30 is minutes and its a parameter
the above query will fetch all the data which are in OPEN status from beginning to sysdate - (30/1440). so i want to modify the query to restrict the complete data , by adding another parameter like DAY
for example if i give 10 as day, it should fetch all the data only in the last 10 days and sysdate-30 minutes.
we should use last_update_date column for restricting the day.
If I dont give any day as input if should fetch all the records from sysdate-30 minutes.
If I dont give minutes it should fetch all the records in OPEN status.
is the question clear enough? My English is bad.
Please suggest me a query..
Simply use OR expressions where you check the parameters for NULL:
select *
from xyz
where status = 'OPEN'
and (last_update_date <= sysdate - (:minutes/1440) or :minutes is null)
and (trunc(last_update_date) >= trunc(sysdate - :days) or :days is null)
This query is not tested.
Please tell me this query is returning any error or somthing that i have missed.
select
*
from
xyz
where
status = 'OPEN'
and
last_update_date <= CASE WHEN #No_Of_Days <> 0 THEN sysdate - #No_Of_Days ELSE NULL END
and
minutes(last_update_date) <= SYSDATE - 30/1440

Datediff function of DQL is not returning results as expected

I am trying to query documentum server using DQL query. Using DATEDIFF function to select data that are created in the current date. Here is the query
SELECT title FROM content_table WHERE DATEDIFF(day, "r_creation_date", DATE(TODAY)) < '1' AND content_type IN ('story','news')
Problem is along with today's data its selecting yesterday's also. Why is less than 1 condition fetching yesterday's data also?
Have tried using DATEDIFF(day, "r_creation_date", DATE(TODAY)) = '0' but that does not fetch any result. I understand even the time comes into picture but as I am using 'day' as the date pattern will it not just calculate difference of the days alone?
You can try this query:
SELECT title FROM content_table WHERE r_creation_date > DATE(TODAY) AND content_type IN ('story','news')
if you need the objects created today (after 00:00, not in the last 24 h)
I should use the GETDATE() function to get the current day
Regards.