如何编码当前日期 - 选择actual_date = 或比current_date>的行?



在下面的SQL for SQL Server 2014(v12.00.6433(中,e.actual_datedatetime Null列。显示的代码导致错误:

Msg 156,Level 15,State 1,Line 13
关键字"CURRENT_DATE"附近的语法不正确。

此处的目的是,我们希望仅查看自当前日期起过去两年半内的所有客户活动。

select distinct 
ac.people_id, ac.first_name, ac.last_name, ac.id_no, 
ad.city, ed.is_service_event, co.description as County,
pe.program_name, pe.program_start_date, pe.program_end_date, 
el.actual_date, el.approved_date, el.program_providing_service, 
el.duration, ed.event_name
from
all_clients_view ac
inner join 
address ad on ad.people_id = ac.people_id
left join 
county co on ad.county = co.county_id
inner join 
program_enrollment_expanded_view pe on pe.people_id = ac.people_id
inner join 
event_log el on ac.people_id = el.people_id
inner join 
event_definition ed on el.event_definition_id = ed.event_definition_id
where 
el.actual_date > CURRENT_DATE() - (365 * 2 + 366 / 2) 

CURRENT_DATE()不是sql server函数。尝试将其替换为GETDATE()

两年半前也可以这样减去30个月:DATEADD(month, -30, GETDATE())

相关内容

最新更新