0
我有應用於外部查詢的日期變量,但我收到一條錯誤消息:v_Date在使用它的上下文中無效 - 嘗試在內部查詢中使用它時。SQL DB2如何將日期變量應用於內部查詢?
你能幫我用時間變量v_Date替換內部查詢中的兩個3/31/2016日期嗎?我需要移動WITH行還是進行雙連接?
WITH ttt as (select '3/31/2016' v_Date FROM SYSIBM.SYSDUMMY1)
SELECT
fpr.ID
fpr.ID_PRICG_MTHDY,
fpr.MARKET_DATE,
fpr.PRICE_AMOUNT AS FIRST_PRICE,
pr.PRICE_AMOUNT AS SECOND_PRICE,
pr2.PRICE_AMOUNT AS THIRD_PRICE,
thr.PRICE_DIFF AS TEST_1,
thr.PRICE_DIFF2 AS TEST_2
FROM PRICE_TABLE_1 fpr
LEFT JOIN PRICE_TABLE0 pr
ON fpr.ID = pr.ID AND pr.MARKET_DATE = '3/31/2016' AND pr.ROLE_TYPE = 'D'
LEFT JOIN PRICE_TABLE0 pr2
ON fpr.ID = pr2.ID and pr2.MARKET_DATE = '3/31/2016' AND 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
WHERE fpr.DT_EXPTN = '1/1/9999'
AND fpr.MARKET_DATE = fpr.SELL_DATE
AND fpr.TYPE = 'F'
AND fpr.ID_PRICG_MTHDY IN (1, 3, 4, 7)
謝謝,完美的作品。 – steveW