SQL DB2 how to apply date variable to inner queries? -
i have date variable have applied outer query, receiving error message: v_date not valid in context used - when trying use on inner queries.
can me replace 2 3/31/2016 dates in inner query time variable v_date? need move line or double join?
with ttt (select '3/31/2016' v_date sysibm.sysdummy1) select fpr.id fpr.id_pricg_mthdy, fpr.market_date, fpr.price_amount first_price, pr.price_amount second_price, pr2.price_amount third_price, thr.price_diff test_1, thr.price_diff2 test_2 price_table_1 fpr left join price_table0 pr on fpr.id = pr.id , pr.market_date = '3/31/2016' , pr.role_type = 'd' left join price_table0 pr2 on fpr.id = pr2.id , pr2.market_date = '3/31/2016' , pr2.role_type = 'p' left join threshold_test_table thr on fpr.id_pricg_mthdy = thr.id_pricg_mthdy join ttt on fpr.market_date = v_date fpr.dt_exptn = '1/1/9999' , fpr.market_date = fpr.sell_date , fpr.type = 'f' , fpr.id_pricg_mthdy in (1, 3, 4, 7)
i start cte first element of from
, can use value anywhere:
from ttt left join price_table_1 fpr on fpr.market_date = v_date left join price_table0 pr on fpr.id = pr.id , pr.market_date = ttt.v_date , pr.role_type = 'd' left join price_table0 pr2 on fpr.id = pr2.id , pr2.market_date = ttt.v_date , pr2.role_type = 'p' left join threshold_test_table thr on fpr.id_pricg_mthdy = thr.id_pricg_mthdy
Comments
Post a Comment