2013-07-03 157 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