如何从 sql server 表获取今天的交易
我有一个事务表,其中包含日期时间数据类型的开始日期和结束日期。
我正在从 vb.net 应用程序传递日期。我在 vb.net 应用程序中编写了以下代码,生成的查询出乎意料:
String.Format("SELECT * FROM {0}{1} WHERE {0}tran_date >= '{2}' and {0}tran_date <= '{3}' ;", _Pre, _Table, DateFrom.Date, DateTo.Date)
这里 DateFrom 和 DateTo 都是日期变量。
它产生的输出如下:
SELECT * FROM rm07transaction
WHERE
rm07tran_date >= '03/16/2011 12:00:00 AM' and
rm07tran_date <= '03/16/2011 12:00:00 AM'
当我查询以查找 03/16/2011 的数据时,它们未填充
I have a transaction table which has start_date and end_date of datetime datatype.
I am passing date from vb.net application. I wrote following code in vb.net application and query generated was somthing un-expected:
String.Format("SELECT * FROM {0}{1} WHERE {0}tran_date >= '{2}' and {0}tran_date <= '{3}' ;", _Pre, _Table, DateFrom.Date, DateTo.Date)
Here Both DateFrom and DateTo are date variables.
It produced output like:
SELECT * FROM rm07transaction
WHERE
rm07tran_date >= '03/16/2011 12:00:00 AM' and
rm07tran_date <= '03/16/2011 12:00:00 AM'
When i make query to find data of 03/16/2011 they are not populated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的示例中,您正在搜索“rm07tran_date”完全设置为“03/16/2011 12:00:00 AM”的行。您想要的是使用“开始日期”列和“结束日期列”。例如:
In your example you are searching for rows that have "rm07tran_date" exactly set to "03/16/2011 12:00:00 AM". What you want is to use the "start date" column and the "end date column". EG: