0

我真的无法理解。

代码-

select * 
from Bill_Detail 
where DateTimeofBilling > '8/18/2013 12:00:00 PM' 
  and DateTimeofBilling < '8/20/2013 12:00:00 AM'

伪代码-

select all 
from Bill_Detail 
where DateTimeofBilling greater than 8/18/2013 
  and DateTimeofBilling less than 8/20/2013

我需要从日期 8/18/2013 到 8/20/2013 获取行,但代码没有返回任何内容。

我认为这足以解释这一点。谁能帮忙?

4

6 回答 6

2

为什么您使用PM(中午,而不是午夜)进行“大于”检查?您的伪代码假定您还想使用 PM。

select * 
from Bill_Detail 
where DateTimeofBilling >= '20130818'-- if you want to include this day completely
  and DateTimeofBilling < '20130820' -- if you want to exclude this day completely
于 2013-08-21T11:51:29.527 回答
0

尝试这个..

select * from Bill_Detail where DateTimeofBilling > '2013/08/18 12:00:00 PM' and DateTimeofBilling < '2013/08/20 12:00:00 AM'
于 2013-08-21T11:45:51.840 回答
0

如果您的列DateTimeofBilling是 datetime 类型,请将其与 date 而不是 varchar 进行比较:

select * 
from Bill_Detail 
where
    DateTimeofBilling >= convert(date, '20130818', 112) and
    DateTimeofBilling < convert(date, '20130821', 112)

这将返回带有 DateTimeofBilling 的行,其中日期大于或等于2013-08-18且小于或等于2013-08-20

于 2013-08-21T11:48:21.943 回答
0

之间使用

SELECT *
FROM Bill_Detail
WHERE DateTimeofBilling BETWEEN '20130818 000000' 
    AND DateTimeofBilling < '2013/08/20 12:00:00 AM'
于 2013-08-21T11:50:03.360 回答
0

尝试这个,

select * from Bill_Detail where DateTimeofBilling between '8/18/2013 12:00:00 PM' and  '8/20/2013 12:00:00 AM'
于 2013-08-21T11:51:53.480 回答
0
SELECT * FROM Bill_Detail WHERE DateTimeofBilling>='8/18/2013 12:00:00 PM' AND DateTimeofBilling<='8/20/2013 12:00:00 AM' ORDER BY DateTimeofBilling
于 2013-08-21T12:29:47.643 回答