[英]How to get record of today's inserted data in SQL Server in C# windows form application
I am developing an app in VS2010 c# to fetch a single row data from SQLServer and insert it to MySQL. 我正在VS2010 c#中开发一个应用程序,以从SQLServer获取单行数据并将其插入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. 在此,我必须检查在SQL Server表名称RAW_S001T01中今天通过一个SQL Server查询插入了多少条记录。
I have tried to Google it but not getting exact answer. 我曾尝试使用Google进行搜索,但未获得确切答案。 I tried below query 我在下面查询
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. 提前致谢。
If you only want records in RAW_S001T01
where Date_Time
column is equals to the today date, you can modify your WHERE clause like this : 如果你只是想在记录RAW_S001T01
其中Date_Time
列等于今天日期,你可以修改你的WHERE这样的条款:
SELECT Date_Time
FROM RAW_S001T01
WHERE Date_Time = CONVERT(date, getdate())
ORDER BY Date_Time DESC
GETDATE()
is an SQLServer function which will return the today date, like 2013-11-20 14:05:54.943
. GETDATE()
是一个SQLServer函数,它将返回今天的日期,例如2013-11-20 14:05:54.943
。 Cast it in DATE
to only keep the date part, ie 2013-11-20
. 在DATE
强制转换,只保留日期部分,即2013-11-20
。
If I've understood your question, you only need to count the number of records added today by the Date_time column. 如果我理解了您的问题,则只需要计算Date_time列今天添加的记录数。 Hope I'm not mistaken. 希望我没有记错。
Try this; 尝试这个;
SELECT Count(Date_Time) as No_Of_records_today
FROM RAW_S001T01
WHERE (Date_Time = getdate())
Thanks for your suggestions got correct answer ie 谢谢你的建议得到正确的答案,即
SELECT Date_Time FROM RAW_S001T01
WHERE Date_Time >= CONVERT(DateTime, DATEDIFF(DAY, 0, GETDATE()))
ORDER BY Date_Time DESC
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.