I wish to use sql query to do some operations.
My 1st sql is shown as below:
(1) select i2.trade_in_discount from invoice i2, model_chassisno mc where i2.trade_in_value <> 0 and i2.model = mc.model and i2.model in('ZFL') and i2.chassis_no = mc.chassis_no
returned 2 resuls:
TRADE_IN_DISCOUNT
------------------------
5000.00
1359.75
2nd sql is shown as below:
(2) select ml.trade_in_amt from model_chassisno mc, invoice
i3, margin_limit ml where i3.model in('ZFL') and
i3.model=ml.model and i3.booking_date <=
ml.effective_date and i3.trade_in_value<>0 order by
ml.effective_date DESC FETCH FIRST 1 ROWS ONLY
returned 1 result:
TRADE_IN_AMT
------------
777
I wish to display my result using sql(1) - sql(2) which will return the result as below:
1
-----------
4223.00 (5000.00-777)
582.75 (1359.75-777)
I tried two ways to do it:
(A) select i2.trade_in_discount from invoice i2,
model_chassisno mc where i2.trade_in_value <> 0 and
i2.model = mc.model and i2.model in('ZFL') and i2.chass
is_no = mc.chassis_no - (select ml.trade_in_amt from
model_chassisno mc, invoice i3, margin_limit ml where
i3.model in('ZFL') and i3.model=ml.model and i3.booking_date <= ml.effective_date and i3.trade_in_value<>0 order by ml.effective_date DESC FETCH FIRST 1 ROWS ONLY)
(B) select i2.trade_in_discount - (select ml.trade_in_amt from model_chassisno mc, invoice i3, margin_limit ml where i3.model in('ZFL') and i3.model=ml.model and i3.booking_date <= ml.effective_date and
i3.trade_in_value<>0 order by ml.effective_date DESC
FETCH FIRST 1 ROWS ONLY) from invoice i2,
model_chassisno mc where i2.trade_in_value <> 0 and
i2.model = mc.model and i2.model in('ZFL') and i2.chassis_no = mc.chassis_no
Both of them return same error:
SQL0104N An unexpected token "FETCH" was found following ".effective_date DESC". Expected tokens may include: "". SQLSTATE=42601
Can anyone tell me how to solve this problem??? in URGENT!!!
My 1st sql is shown as below:
(1) select i2.trade_in_discount from invoice i2, model_chassisno mc where i2.trade_in_value <> 0 and i2.model = mc.model and i2.model in('ZFL') and i2.chassis_no = mc.chassis_no
returned 2 resuls:
TRADE_IN_DISCOUNT
------------------------
5000.00
1359.75
2nd sql is shown as below:
(2) select ml.trade_in_amt from model_chassisno mc, invoice
i3, margin_limit ml where i3.model in('ZFL') and
i3.model=ml.model and i3.booking_date <=
ml.effective_date and i3.trade_in_value<>0 order by
ml.effective_date DESC FETCH FIRST 1 ROWS ONLY
returned 1 result:
TRADE_IN_AMT
------------
777
I wish to display my result using sql(1) - sql(2) which will return the result as below:
1
-----------
4223.00 (5000.00-777)
582.75 (1359.75-777)
I tried two ways to do it:
(A) select i2.trade_in_discount from invoice i2,
model_chassisno mc where i2.trade_in_value <> 0 and
i2.model = mc.model and i2.model in('ZFL') and i2.chass
is_no = mc.chassis_no - (select ml.trade_in_amt from
model_chassisno mc, invoice i3, margin_limit ml where
i3.model in('ZFL') and i3.model=ml.model and i3.booking_date <= ml.effective_date and i3.trade_in_value<>0 order by ml.effective_date DESC FETCH FIRST 1 ROWS ONLY)
(B) select i2.trade_in_discount - (select ml.trade_in_amt from model_chassisno mc, invoice i3, margin_limit ml where i3.model in('ZFL') and i3.model=ml.model and i3.booking_date <= ml.effective_date and
i3.trade_in_value<>0 order by ml.effective_date DESC
FETCH FIRST 1 ROWS ONLY) from invoice i2,
model_chassisno mc where i2.trade_in_value <> 0 and
i2.model = mc.model and i2.model in('ZFL') and i2.chassis_no = mc.chassis_no
Both of them return same error:
SQL0104N An unexpected token "FETCH" was found following ".effective_date DESC". Expected tokens may include: "". SQLSTATE=42601
Can anyone tell me how to solve this problem??? in URGENT!!!