displaying records with a date at least one day greater then or = to today - sql

I have a field in a table called DATEF. It displays dates as follows: 2013-11-25 08:30:00.000. The field is used to show appointment dates. What I need to show are future appointment dates from today or = to today. (Getdate) for some reason this is not working for me today. Appreciate the help. Thank you.

Try this... you're probably failing to factor in the time component. (This is for SQL Server, you'll have to find the equivalent for your respective environment)
SELECT <SOMETHING>
FROM TABLE
WHERE DATEF >= CONVERT(DATE,GETDATE())

Related

Include records occurring within a date period

50 records in databank. I prepared a query to select contracts with ending dates between 1/1/2019 and 12/31/2020. Some of the records have dates outside the 12/31/2020; 12/31/2021. I want those records included as they were active during the queried period.
The between query only returns records with the ending date of 12/31/2020. I changed the criteria to end period between 1/1/2019 and 12/31/2021 and not 12/31/2022. That returns records before end end date of 12/31/20 and outside the start of the end period of 1/1/2019.
I've tried about 10 other things (can't remember all of them) regardless am not getting the results I need.
I'm not VBA/SQL friendly, I'm a query kind of user. Sorry if that makes my question a little more difficult.
Thank you soooo much for any direction you can give me!!
select *, DATE_FORMAT(*datetime_column*,'%m/%d/%Y') from *table_name* where *datetime_column* between '1/1/2019' and '12/31/2020'
I think the format of date leads to 'query don't satisfy correct result' problem. You could convert the date to this format and check the result

Formatting Day Time X Axis in SSRS Charts

I am working on a SSRS report which compares data of 2 given months. I'm categorising the chart based on Day and time in the following format 1, 6:00 AM. I get this column from the T-SQL itself. But the axis does not come properly. It looks like below now which doesn't make sense. I want it to be in order from 1st to 30th with the time component.
I guess I need some kind of sorting on X-axis with respect to date time. Please help!
After deleting from sorts from chart I'm getting some extra repitive dates after comparing all 30 days of both months. Data from the query looks alright to me!
Thank you!
Ok. Large query
You X-axis are show value in format date,hh mm tt Right ?
Then you want to sort them with day number 1 - 30.
From your query I suggest you add 1 field is like this CAST(SampleCollected AS DATE) [orders] and use this field in Order in Query or Sort on SSRS (not recommend ) and if you use Order in Query must delete sort condition on chart sort.
But if result still not you want try to add MONTH(SampleCollected) As MonthG to order again like this
ORDER BY MONTH(SampleCollected),CAST(SampleCollected AS DATE)
Hope it's Help.

How to select SQL Server data based on today's date and time?

I'm using SQL Server to COUNT some data which originates from a HTML table. I want to COUNT total rows in the database based on today's date. And then after the date hits tomorrow's date, to set the COUNT value back to zero and to restart the count back from the start.
Is there a query that can help me fetch data based on current date and time?
Something like this:
SELECT COUNT(data_id)
FROM table1
WHERE clock_time BETWEEN 000000 AND 235959
AND date_time IS TODAY's DATE (or something like that)
GROUP BY XXX
ORDER BY XXX
After the clock hits tomorrow's date, I want to reset the COUNT back to zero, and to start a new count back from 00:00:00.
I know there is NOW() query but as far as I know it only shows the date.
Someone told me I could use WHERE DATE(date)=CURDATE() but the SQL Server won't work with that.
Thank you...
You can use convert function like this
where convert(Date,date_time)= CONVERT(Date,GETDATE())
Need not to use time as you want today's data.
Try this one
SELECT COUNT(data_id) FROM table1
WHERE convert(date,date_time) = getdate()

Same dates from and to not showing data

the following is the sql being executed in my Crystal report.
There seems to be an issue with the same date request. Sometimes it shows data, other times not. We have data every day, we are a mass market company. Is there anything i can do for the sql to do select when from and to dates are the same?
SELECT "OEHIS1"."ODORD#", "OEHIS1"."ODORDT", "OEHIS1"."ODNTU$", "OEHIS1"."ODSHP#", "ICPRT1"."IARC11", "OEHIS1"."ODORDD", "ICPRT1"."IARCC4", "OEHIS1"."ODQTY#", "OEHIS1"."ODRQSD", "MFHHMH"."MHAWGT", "OEHIS1"."ODPRT#", "OEHIS1"."ODPRLC"
FROM ("S10M10"."ASTCCDTA"."EODDETAILS" "OEHIS1" INNER JOIN "S10M10"."ASTDTA"."ICPRT1" "ICPRT1" ON "OEHIS1"."ODPRT#"="ICPRT1"."IAPRT#") INNER JOIN "S10M10"."DLIB"."MFHHMH" "MFHHMH" ON "OEHIS1"."ODORD#"="MFHHMH"."MHORDP"
WHERE "OEHIS1"."ODPRT#" NOT LIKE 'FR%' AND "ICPRT1"."IARCC4"='FIN' AND "OEHIS1"."ODORDD"=20141027 AND NOT ("ICPRT1"."IARC11"='' OR "ICPRT1"."IARC11"='DRS') AND ("OEHIS1"."ODORDT"='CSA' OR "OEHIS1"."ODORDT"='CUS' OR "OEHIS1"."ODORDT"='INT' OR "OEHIS1"."ODORDT"='N4H' OR "OEHIS1"."ODORDT"='NFM' OR "OEHIS1"."ODORDT"='RTR') AND NOT ("OEHIS1"."ODPRLC" LIKE 'CMY%' OR "OEHIS1"."ODPRLC" LIKE 'DSC%' OR "OEHIS1"."ODPRLC" LIKE 'LGC%' OR "OEHIS1"."ODPRLC" LIKE 'X%')
ORDER BY "ICPRT1"."IARC11"
Migrated my comment to an answer, since that seemed to work for you.
I have very little CR experience, but with SQL you usually want to select between the day you want and the day after if you want results for today. That's because today, for example, is 10/27/2014, with no time. This defaults to midnight. If the date is the same on both sides, you'll only get results that happened at exactly midnight. Your query should be between 10/27/2014 and 10/28/2014 (midnight this morning to midnight tomorrow).

How to extract dates with datatye DATETIME from colum A in table X and put them into Table Y while changing datatype into DATE

Long title, easy meaning:
How is it possible to extract from a date like "2014-04-04 10:47:30.000", which is stored in one column, it's components like year, month and day?
I'm not interested in the time.
For example, I have a table called "Incidents". Inside the table we got a column called "IncidentID" and a column called "ReportingDate", in which dates like the above-mentionend are stored. Let's say we have about 50k Incidents, therefore we have also 50k dates.
A year has 365 days. I want to query for the count of the Incidents, which were reported on different dates - for instance on the 5th of October 2013.
So: How can I get the components of the date and put them into another table while having own columns for the components and how can I query for the Incidents as well?
I guess at first I have to change the datatype of the date from DATETIME to DATE, but I'm not quite sure how to go further. May anyone help me while giving me a code and explains me what it does for a sql-noob? :-)
To achieve this
I want to query for the count of the Incidents, which were reported on
different dates - for instance on the 5th of October 2013.
you haven't do this:
I guess at first I have to change the datatype of the date from
DATETIME to DATE, but I'm not quite sure how to go further.
Just query
SELECT
IncidentID
FROM incidents
WHERE ReportingDate >= '20131005'
AND ReportingDate < '20131006'