sql - Can I use a user defined database function in a query in Pentaho Report Designer? -
i'm reporting on data 2 tables don't have sane way join together. it's inventory in 1 table, sales in other, , i'm trying days of inventory on hand dividing two. since couldn't think of way join tables abstracted 1 query database function , called other.
here function definition:
create or replace function avgsales(date, text, text, integer) returns numeric ' select sum(quantity)/(65.0*$4/90.0) thirty_day_avg data_867 join drug_info on drug_info.dist_ndc = trim(leading ''0'' data_867.product_ndc) rpt_start_dt>= $1-$4 , rpt_end_dt<= $1 , drug_info.drug_name = $2 , wholesaler_name = $3 ' language sql;
and here report query:
select (sum("data_852"."za02")/5)/avgsales(date '2010-11-30', 'semprex d 100ct', 'mckesson', 30) doh "data_852" join "drug_info" on "drug_info"."dist_ndc" = "data_852"."lin03" join "wholesaler_info" on trim("data_852"."isa06") = trim("wholesaler_info"."isa06") (za01 = 'qa' or za01 = 'qp' or za01 = 'qi') , "data_852"."xq02">= date '2010-11-30'-5 , "data_852"."xq03"<='2010-11-30' , drug_info.drug_name = 'semprex d 100ct' , wholesaler_info.wholesaler_name = 'mckesson' ;
as here, run in pentaho report designer hard coded. when parameterize values clause complains syntax error @ $1. looking @ queries postgres receives, pentaho passes query it's parameters using $1, $2, etc. think there might conflict same variable names being used in our function, or maybe it's data type problem.
what causing error? possible use function in report query? if not, how can similar using report designer?
it possible. using postgres 8.4 , rd 3.7
create function ret_p(text) returns text $$ select $1; $$ language sql immutable;
report designer query
select * ret_p(${p_val});
where p_val parameter name defined in rd
Comments
Post a Comment