我想要数据表中的链接,其中徽标链接为 <= fromdate and >= 今日。
我编写此查询是为了获取值
select * from getlogo
select * from getlogo
where (Convert(date,logofrom) >= getdate()) and (Convert(date,logoto) <= getdate())
and active=0
today = 03/25/2015
from = database.value logofrom
to = database.value logoto
how to compare this and get value
结果:
如果您想要徽标具有今天所在的日期范围,则反转条件:
(Convert(date,logofrom) <= getdate()) and (Convert(date,logoto) >= getdate())
这将在您的示例中返回带有
id = 2
的徽标。
您应该 CAST GetDate 以便包含边缘上的日期:
SELECT *
FROM getlogo
WHERE CAST(logofrom AS DATE) <= CAST(GETDATE() AS DATE)
AND CAST(logoto AS DATE) >= CAST(GETDATE() AS DATE)
AND active = 0
如果根据您的描述,您需要第二条记录作为结果..
使用此查询
select * from getlogo where getdate() between convert(datetime,logofrom)
and convert(datetime,logoto) and active=0