我正在使用
Select Customer.QuoteID, Quote.QuoteID
From Customer, Quote
Where Customer.QuoteID=Quote.QuoteID
Order By Quote.QuoteID
我想指定一个日期范围(Quote.CreationDate)或者至少显示大于31/03/2013的日期,但我不确定如何添加它?
我希望在Delphi中使用一个对话框来最终选择日期范围......
答案 0 :(得分:6)
要按日期范围限制,您可以执行以下操作:
Select Customer.QuoteID, Quote.QuoteID
From Customer, Quote
Where Customer.QuoteID = Quote.QuoteID
and Quote.CreationDate between :date_from and :date_to
Order By Quote.QuoteID
其中:date_from
和:date_to
是您的日期参数
答案 1 :(得分:2)
您可以将这些添加到where子句:
Select Customer.QuoteID, Quote.QuoteID
From Customer, Quote
Where Customer.QuoteID=Quote.QuoteID
And Quote.CreationDate > '2013-03-31'
Order By Quote.QuoteID
这是标准的ANSI连接语法,这通常是首选,在这种情况下我觉得更容易阅读:
Select Customer.QuoteID, Quote.QuoteID
From Customer
Inner Join Quote On Customer.QuoteID = Quote.QuoteID
Where Quote.CreationDate > '2013-03-31'
Order By Quote.QuoteID
或者,如果您正在寻找两个日期之间的范围:
Select Customer.QuoteID, Quote.QuoteID
From Customer
Inner Join Quote On Customer.QuoteID = Quote.QuoteID
Where Quote.CreationDate >= '2013-03-31'
AND Quote.CreationDate <= '2013-04-02'
Order By Quote.QuoteID
最后,在某些RDBMS平台上,您也可以使用BETWEEN
operator,但我上一个示例中的语法将始终有效。