我在访问中使用以下查询来构建数据库。我想将此查询用于不同的日期范围和不同的" ndc"数。在下面的查询中我使用了问号,但没有得到结果。我知道我可以用吗?在Sql server中,但teradata不接受歧义。我能以某种方式做到这一点,而不是必须指定日期范围和" ndc"数?
select ls.str_nbr, ndc11, wic_nbr, prod_name, pkg_sz, pkg_qty, count(*) as rx_volume, sum(fill_qty_dspn), sum(fill_gross_profit_dlrs), sum(fill_revenue_dlrs), sum(fill_cost_dlrs)
from (select * from prdedwvwh.prescription_fill_sold where fill_sold_dt Between ? And ? ) as pf
inner join
prdedwvwh.prescription_fill_sales_metric pfsm
on
pf.str_nbr=pfsm.str_nbr and
pf.rx_nbr=pfsm.rx_nbr and
pf.rx_fill_nbr= pfsm.rx_fill_nbr and
pf.rx_partial_fill_nbr =pfsm.rx_partial_fill_nbr and
pf.fill_enter_dt=pfsm.fill_enter_dt and
pf.fill_sold_dt=pfsm.fill_sold_dt
inner join
prdedwvwh.drug_cur dd
on
pf.drug_id=dd.drug_id
and ndc11 in ('?')
inner join
prdedwvwh.location_store ls
on
pf.str_nbr=ls.str_nbr
and ls.mail_retail_ind ='RETAIL'
group by 1,2,3,4,5,6
答案 0 :(得分:0)
您提交此查询的客户端工具是什么?
为了能够在任何客户端使用它,您需要在存储过程中使用动态SQL或创建一个宏,如:
replace macro mymac(ndc integer, start_dt date, end_date date)
as
( select ls.str_nbr, ndc11, wic_nbr, prod_name, pkg_sz, pkg_qty,
count(*) as rx_volume, sum(fill_qty_dspn), sum(fill_gross_profit_dlrs),
sum(fill_revenue_dlrs), sum(fill_cost_dlrs)
from (select * from prdedwvwh.prescription_fill_sold
where fill_sold_dt Between :start_dt And :end_dt ) as pf
inner join
prdedwvwh.prescription_fill_sales_metric pfsm
on
pf.str_nbr=pfsm.str_nbr and
pf.rx_nbr=pfsm.rx_nbr and
pf.rx_fill_nbr= pfsm.rx_fill_nbr and
pf.rx_partial_fill_nbr =pfsm.rx_partial_fill_nbr and
pf.fill_enter_dt=pfsm.fill_enter_dt and
pf.fill_sold_dt=pfsm.fill_sold_dt
inner join
prdedwvwh.drug_cur dd
on
pf.drug_id=dd.drug_id
and ndc11 = :ndc
inner join
prdedwvwh.location_store ls
on
pf.str_nbr=ls.str_nbr
and ls.mail_retail_ind ='RETAIL'
group by 1,2,3,4,5,6;
) ;
但正如Andrew已经写过的那样,你不能在一个参数内传递多个值(至少在TD14之前不是那么简单)。