如何在sql select语句中为两个不同的字段使用BETWEEN命令? [英] how to use BETWEEN command for two different fields in sql select statement?
本文介绍了如何在sql select语句中为两个不同的字段使用BETWEEN命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如上所述,我想做一个如下代码:
选择 UniformGroupID,价格来自 UniformPrice where (datename(年, CONVERT ( datetime ,EffectiveDate, 103 ))= ' 2012'
和 datename(MONTH, CONVERT ( datetime ,EffectiveDate, 103 ))= ' 10月')
之间的(日期名称(年份, CONVERT ( datetime ,CloseDate, 103 )= ' 2999' 和 datename(MONTH, CONVERT ( datetime ,CloseDate, 103 ))= < span class =code-string>' December')
我知道我错误地使用了BETWEEN命令,但概念是这样的,所以我应该如何设置它或任何其他可用作BETWEEN命令的命令?
谢谢。
N $ P
解决方案
< blockquote> P
试试这个
SELECT
UniformGroupID,
price
FROM
UniformPrice
WHERE
CONVERT ( datetime ,EffectiveDate, 103 ) BETWEEN ' 1/10/2012' AND ' 31/12/2999'
AND
CONVERT ( datetime ,CloseDate, 103 ) BETWEEN ' 1/10/2012' AND ' 31/12/2999'
希望这有帮助
--RDBurmon
singping想要这样,试试看
SELECT
UniformGroupID,
price
FROM
Un iformPrice
WHERE
DATEPART(yyyy,EffectiveDate) BETWEEN ' 2012' AND ' 2999'
AND
DATEPART(mm,CloseDate ) BETWEEN ' 10' AND ' 12'
Hi,
As stated above subject, I would like to do a code as following:
select UniformGroupID, price from UniformPrice where (datename(YEAR, CONVERT (datetime,EffectiveDate, 103))='2012'
and datename(MONTH, CONVERT (datetime,EffectiveDate, 103))='October')
between (datename(YEAR, CONVERT (datetime,CloseDate, 103)='2999' and datename(MONTH, CONVERT (datetime,CloseDate, 103))='December')
I know I''m wrongly using the BETWEEN command but the concept is something like that so how should I set it or any other command that can be used as BETWEEN command?
Thanks.
N$P
解决方案
P
Try this
SELECT UniformGroupID, price FROM UniformPrice WHERE CONVERT (datetime,EffectiveDate, 103) BETWEEN '1/10/2012' AND '31/12/2999' AND CONVERT (datetime,CloseDate, 103) BETWEEN '1/10/2012' AND '31/12/2999'
Hope this helps
--RDBurmon
singping wants this way, try and see
SELECT UniformGroupID, price FROM UniformPrice WHERE DATEPART(yyyy,EffectiveDate) BETWEEN '2012' AND '2999' AND DATEPART(mm,CloseDate) BETWEEN '10' AND '12'
这篇关于如何在sql select语句中为两个不同的字段使用BETWEEN命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文