如何在C#windows窗体应用程序中获取SQL Server中今天插入数据的记录。 [英] How to get record of today's inserted data in SQL Server in C# windows form application.
问题描述
我正在开发一个VS2010 c#中的应用程序来从SQLServer获取单行数据并将其插入MySQL。
在这里我要查看多少今天插入的记录在SQL Server表名RAW_S001T01中有一个SQL Server查询。
我试过谷歌但没有得到确切答案。
我在下面尝试查询
SELECT Date_Time
FROM RAW_S001T01
WHERE (Date_Time = {fn CURDATE()})
ORDER BY Date_Time DESC
但没有得到正确的输出。
请帮我正确查询。
提前致谢。
好的。得到了错误的问题;)
所以我用OG的替代查询更新它。
如果您使用的是SQL Server 2008年或之后您可以转换为DATE类型,从而删除日期时间的时间部分。
SELECT Date_Time FROM RAW_S001T01
WHERE Date_Time> = CAST( GETDATE() AS DATE )
ORDER BY Date_Time DESC
< blockquote>尝试:
SELECT Date_Time FROM RAW_S001T01
WHERE Date_Time> = CONVERT ( DateTime ,DATEDIFF(DAY, 0 ,GETDATE()))
ORDER BY Date_Time DESC
CONVERT(DateTime,DATEDIFF(DAY,0,GETDATE()))
part返回昨晚午夜,所以查询返回今天的所有记录。
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
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.
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.
SELECT Date_Time FROM RAW_S001T01 WHERE Date_Time >= CAST(GETDATE() AS DATE) ORDER BY Date_Time DESC
Try:
SELECT Date_Time FROM RAW_S001T01 WHERE Date_Time >= CONVERT(DateTime, DATEDIFF(DAY, 0, GETDATE())) ORDER BY Date_Time DESCThe
CONVERT(DateTime, DATEDIFF(DAY, 0, GETDATE()))
part returns midnight last night, so the query returns all records for today.
这篇关于如何在C#windows窗体应用程序中获取SQL Server中今天插入数据的记录。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!