Query date ranges between two fields - sql-server

I need to select from a table that has two fields , a start date and an end date , selecting the row that the current date is. Look at the image ...how do i select the row that encompasses the date range 91/201 - 9/15/2018 ? Somehow this was flagged as a duplicate. I am NOT attempting to find overlap. I am attempting to find the row that represents a given date. Say , one table has a field that has the value 9/5/2018 ....how do I select the row that has a start date of 9/1/2018 and end date of 9/15/2018

Related

Get latest date in a column based on a duplicate value in a table using Powerautomate

I have a table in dataverse, that has a date, telephone number, and ID columns as below.
Date
ID
Telnum
12/6/202
abcd
8421678
12/9/2020
abce
8421679
12/13/2020
abcg
8421678
From the table the 1st and 3rd column have the same Tel num, but different dates and ID. What am trying to achieve is on the same table in a column called end date,post the last date with regards to the tel num this is basically the 1st date of the date the number switched to a new record based on ID.
The table am trying to come up with looks as below
Date
ID
Telnum
Date To
12/6/202
abcd
8421678
12/13/2020
12/9/2020
abce
8421679
12/13/2020
abcg
8421678
What I've tried is create an Instant flow, List Records(The table name), List records 2 (Table name but this tome with filters {The filters are (tel num eq tel num and id ne id)}, Then Update record to populate the end date.
What am missing is a step to get the max or latest date of the column that I will append to the date to mapping.
Any idea on how to achieve this will be highly appreciated.
TIA.
According to the description of your requirement, it seems you want to add one more column(named Date To) for the table and set the current date(you mentioned as max or latest date) as the value of the new column.
The second table you provide shows the value of DateTo should be like 12/13/2020, but if you just set the date with the format month/day/year, it can't help you distinguish the two records which has same Telnum because they are both 12/13/2020. So you should set the value of DateTo with format of 2020-12-21T07:23:34.5951356Z. To implement it, you can use utcNow() method shown like below screenshot.
If I misunderstand your requirement, please let me know and provide more details about your question.

KDB Select from partitioned table where date is less than a given date - 1 day

I would like to select from a partitioned table where the date is the highest date strictly below a given date d.
I can do the following:
d:2019.10.02;
{select from x where date = max date} select from t where date < d
where t is my partitioned table.
The issue with the above query is that it is very slow as it has to first load all the dates strictly older than d, and then taking the max date out of it.
To select all the dates that are earlier than your specified date you can use the select statement below:
select from t where date=max date where date<d
Where t is your partitioned table and d is your specified date.
If you just want to select from the max date in a date partitioned hdb
Lets assume that the max populated date partition less than 2019.08.20 is 2019.08.07
q)d:2019.08.20
q)select from t where date=max date where date<d
This is because the partition type is available as a variable once you load into a DB, (i.e,. date, month, int etc). This will be the .Q.pf variable.
select from table where date=(last .Q.pv where .Q.pv < d)
kdb+ stores a variable in memory which contains all the dates within your db.
select from telemetry where date=desc[date]1
Above where clause will sort this by largest ->smallest
Selecting index 1 will filter the max date out of your query (without first querying the entire dataset).

SSRS date/time parameter

I have a ssrs report that has a date/time parameter that allows the user to select the date when running report. how to I get it to exclude the time part of the date field.
currently the field in the db is a date/time field so when I run query
select count(*) from table where date <= #dateparameter
it is not including records where the time part of field is greater than 00.00.00
how can I ignore the time part so all records are returned for that date
The simplest (and probably best performance) solution would be to add a day to the date passed by the user amd change the <= to <:
select count(*) from table where date < DATEADD(DAY, 1, #dateparameter)

SQL Server: Get the last row entries (more than one) with sql query

Scenario: a user will copy and paste data (multiple rows) from an Excel sheet onto my webpage and press submit. When this occurs, the data will be saved into a SQL Server table. The current date will also be saved next to each row.
Now, in another gridview, I would like to view only these multiple rows that have been pasted /saved to DB that certain day.
So I was thinking about using TOP / MAX(date) but Top returns specified rows only, and MAX only 1 row.
Anyone out there that has done this before or can help get a working query?
Use TOP WITH TIES in order to get all last entries:
SELECT TOP(1) WITH TIES
...
ORDER BY submit_date DESC;
Is "that certain day" based on a specific day or a 24 hour interval?
You can make the gridview query the data where the date field is higher than or equal to dateadd(dd, -1, getdate())
Or if you mean the current day as in the current date, where the date is equal to the date of getdate.

SQL date related

Hi all i want to take record from table named Tblbatch where batch starting date should be from augest 2007 to july 2010...
I want to fetch such records which came in between this two dates
Select * from Tblbatch where startDate between '01-08-2007' and '31-07-2010'
provided you have a datetime column "startDate"
Note : that using between includes both the dates specified.
If you want to avoid the dates either change the boundary dates to + - 1 respectively or use > and < conditions

Resources