如果我的问题正确,以下内容Query
对您有用。
Select *
FROM Events
WHERE --CONVERT(DATE,GETDATE()) BETWEEN
CONVERT(date,dateadd(day,datediff(day,1,GETDATE()),0)) BETWEEN
CAST((CAST(case when CAST([BeginMonth] as Varchar)> (select datepart(month,getdate()))
THEN (select datepart(YEAR,getdate())-1)
when CAST([BeginMonth] as Varchar)= (select datepart(month,getdate()))
AND CAST([BeginDay] as Varchar)> (select datepart(month,getdate()))
THEN (select datepart(YEAR,getdate())-1)
when CAST([BeginMonth] as Varchar)= (select datepart(month,getdate()))
AND CAST([BeginDay] as Varchar)= (select datepart(month,getdate()))
THEN (select datepart(YEAR,getdate()))
when CAST([BeginMonth] as Varchar)= (select datepart(month,getdate()))
AND CAST([BeginDay] as Varchar)< (select datepart(month,getdate()))
THEN (select datepart(YEAR,getdate()))
ELSE (select datepart(YEAR,getdate())) END AS VARCHAR)
+'-'+
CAST([BeginMonth] as Varchar)
+'-'+
CAST([BeginDay] as Varchar)) as DATE)
AND
CAST((CAST(case when CAST([BeginMonth] as Varchar)> (select datepart(month,getdate()))
THEN (select datepart(YEAR,getdate())-1)
when CAST([BeginMonth] as Varchar)= (select datepart(month,getdate()))
AND CAST([BeginDay] as Varchar)> (select datepart(month,getdate()))
THEN (select datepart(YEAR,getdate())-1)
when CAST([BeginMonth] as Varchar)= (select datepart(month,getdate()))
AND CAST([BeginDay] as Varchar)= (select datepart(month,getdate()))
THEN (select datepart(YEAR,getdate()))
when CAST([BeginMonth] as Varchar)= (select datepart(month,getdate()))
AND CAST([BeginDay] as Varchar)< (select datepart(month,getdate()))
THEN (select datepart(YEAR,getdate()))
ELSE (select datepart(YEAR,getdate()))+1 END AS VARCHAR)
+'-'+
CAST([BeginMonth] as Varchar)
+'-'+
CAST([BeginDay] as Varchar)) as DATE)
SQL 小提琴
更新的小提琴
我得到了我的Mistake.
Select *
FROM Event
WHERE CONVERT(DATE,GETDATE()) BETWEEN
CAST((CAST(case when CAST([BeginMonth] as Varchar)> (select datepart(month,getdate()))
THEN (select datepart(YEAR,getdate())-1)
when CAST([BeginMonth] as Varchar)= (select datepart(month,getdate()))
AND CAST([BeginDay] as Varchar)> (select datepart(month,getdate()))
THEN (select datepart(YEAR,getdate())-1)
when CAST([BeginMonth] as Varchar)= (select datepart(month,getdate()))
AND CAST([BeginDay] as Varchar)= (select datepart(month,getdate()))
THEN (select datepart(YEAR,getdate()))
when CAST([BeginMonth] as Varchar)= (select datepart(month,getdate()))
AND CAST([BeginDay] as Varchar)< (select datepart(month,getdate()))
THEN (select datepart(YEAR,getdate()))
ELSE (select datepart(YEAR,getdate())) END AS VARCHAR)
+'-'+
CAST([BeginMonth] as Varchar)
+'-'+
CAST([BeginDay] as Varchar)) as DATE)
AND
CAST((CAST(case when CAST([EndMonth] as Varchar)> (select datepart(month,getdate()))
THEN (select datepart(YEAR,getdate()))
when CAST([EndMonth] as Varchar)= (select datepart(month,getdate()))
AND CAST([EndDay] as Varchar)> (select datepart(month,getdate()))
THEN (select datepart(YEAR,getdate()))
when CAST([EndMonth] as Varchar)= (select datepart(month,getdate()))
AND CAST([EndDay] as Varchar)= (select datepart(month,getdate()))
THEN (select datepart(YEAR,getdate())+1)
when CAST([EndMonth] as Varchar)= (select datepart(month,getdate()))
AND CAST([EndDay] as Varchar)< (select datepart(month,getdate()))
THEN (select datepart(YEAR,getdate())+1)
ELSE (select datepart(YEAR,getdate())) END AS VARCHAR)
+'-'+
CAST([EndMonth] as Varchar)
+'-'+
CAST([EndDay] as Varchar)) as DATE)
SQL 小提琴
我希望这一次你会满意。
如果您不想使用Today's
Date 并且您有Predefined
日期,请替换GETDATE()
为您的predefined
Datetime 值。
是的,它Datetime