Click here to Skip to main content
15,888,733 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am developing an app in VS2010 c# to fetch a single row data from SQLServer and insert it to MySQL.

In this I have to check that how many records inserted today with one SQL Server query in SQL Server table name RAW_S001T01.

I have tried to Google it but not getting exact answer.
I tried below query
SQL
SELECT        Date_Time
FROM            RAW_S001T01
WHERE        (Date_Time = { fn CURDATE() })
ORDER BY Date_Time DESC


but not getting correct output.

Please help me with correct query.

Thanks in advance.
Posted
Updated 25-Nov-19 17:29pm

OK. Got the question wrong ;)
So I'm updating it with an alternative query to OG.

If you're using SQL Server 2008 or later you can cast to the DATE type thus removing the time part of the datetime.

SQL
SELECT Date_Time FROM RAW_S001T01
WHERE  Date_Time >= CAST(GETDATE() AS DATE)
ORDER BY Date_Time DESC
 
Share this answer
 
v2
Comments
Karale 20-Nov-13 8:02am    
@Nicholas Marty I just don't need count I need values of date_time column.
Karale 20-Nov-13 8:48am    
@Nicholas Marty yap it's working now.. :)
Try:
SQL
SELECT Date_Time FROM RAW_S001T01
WHERE  Date_Time >= CONVERT(DateTime, DATEDIFF(DAY, 0, GETDATE()))
ORDER BY Date_Time DESC
The CONVERT(DateTime, DATEDIFF(DAY, 0, GETDATE()))part returns midnight last night, so the query returns all records for today.
 
Share this answer
 
Comments
Karale 20-Nov-13 8:05am    
@OriginalGriff it's perfect..!!! I can say just AWESOME..!!! Thank you.
OriginalGriff 20-Nov-13 8:20am    
You're welcome!
SELECT * FROM TABLE
 where create_date between Dateadd(DAY, Datediff(DAY, 0, Getdate()) , 0)
 and DATEADD(second, -1, Dateadd(DAY, Datediff(DAY, 0, Getdate() + 1) , 0)) ;


SELECT * FROM TABLE
 where create_date between '11/26/2019 00:00:00' and '11/26/2019 23:59:59';
 
Share this answer
 
Comments
Richard Deeming 27-Nov-19 13:58pm    
How often have you written an application which sets the "created date" to a date in the future?

Assuming you haven't, you don't need the upper-bound on the date column.

Which makes this solution essentially the same as the two accepted solutions from 2013.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900