2013-07-03 112 views
2

什么是正确的查询?Reporting Services - 连接字符串和参数

我想使“年”的参数:

select distinct 
p.id "pub_id" 
from 
publication "p", organisation_association "oa", organisation "o", localized_string_text "lst_org" 
where 
p.id = oa.publication_id 
and oa.organisation_id = o.id 
and o.name_id = lst_org.localized_string_id 
and p.submission_year = ? 
and exists (select 1 
     from 
     publication "p2", organisation_association "oa2", organisation "o2" 
     where 
     p2.id = p.id 
     and p2.id = oa2.publication_id 
     and oa2.organisation_id = o2.id 
     and o2.period_end_date < date ? + '-01-01') 

然而在最后一行的拼接产生一个语法错误。

回答

3

如果该参数为一年字符串传递:

and o2.period_end_date < date (? || '-01-01')) 

如果它是一个日期:

and o2.period_end_date < date_trunc('year', ?) 

如果是年数:

and o2.period_end_date < date (?::text || '-01-01')) 
+0

感谢Clodo阿尔内托!它完美的工作!一次又一次,我被这些论坛的力量所压倒! – pmelch