postgresql - Reporting Services - 连接字符串和参数

标签 postgresql service parameters reporting concatenation

这里正确的查询是什么?

我想将“年份”作为参数:

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')

但是最后一行的串联会产生语法错误。

最佳答案

如果参数作为年份字符串传递:

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'))

关于postgresql - Reporting Services - 连接字符串和参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17442072/

相关文章:

bash - for循环找出unix中目录是否存在

c++ - 变量用作 C 中的函数参数后出错?

java - 在 Java 中调用传递给数组的方法

c# - 调用 SOAP 服务时参数作为 null 传递

postgresql - Postgres - 如何连接两列?

sql - PostgreSQL/Oracle => 查询以对层次值进行分组和计数

postgresql - 无法访问在 docker 入口点文件中创建的 postgres 扩展,直到我在 psql 中手动创建它

windows - 调试 "service failed to start"Windows Installer 错误

c++ - 如何将用户返回到模拟之前的状态?

postgresql - 转换对 PostgreSQL 的访问?