我想在birt报告中传递一个参数,并在多个地方使用它,例如:
SELECT * FROM tab1 WHERE startDAte = trunc(sysdate)
UNION
SELECT *FROM tab1 WHERE startDate= trunc(sysdate-1)
所以我想把sysdate变成一个变量:
SELECT * FROM tab1 WHERE startDAte = trunc(?)
UNION
SELECT *FROM tab1 WHERE startDate= trunc(?-1)
我该怎么做?感谢
答案 0 :(得分:0)
这已在Reusing an anonymous parameter in a prepared statement
中得到解答如果您的数据库是Oracle,您还可以使用以下语法:
WITH params AS
( select ? as p_date,
? as p_whatever,
...
from dual
)
SELECT tab1.* FROM tab1, params WHERE tab1.startDate = trunc (params.p_date)
UNION
SELECT tab1.* FROM tab1, params WHERE startDate= trunc (parms.p_date - 1)
请注意,不会对性能产生负面影响,因为数据库足够聪明,可以检测到params内联视图只包含一行。