Hi Shelley MKG,
I don't think the select statement used for the cursor c1 will compile.
I doubt my understanding about your problem. Hence i like to explain my understanding before stating the solution.
My Understanding:
Three tables are involved in your problem: OfferInstance(offerId, offerCode), OfferToProduct(offerId, productId), and Product(productId, materialNum).
Input to the procedure is offerCode. The materialNum's related to the offerCode (through OfferInstance.offerId = OfferToProduct.offerId AND OfferToProduct.productId = Product.productId) have to be inserted into another table.
Solution:
-------------------------------------------------------------------
CREATE PROCEDURE TEST(IN offer_code_in char(6))
LANGUAGE SQL
BEGIN
-- For each row returned by the select statement,
-- the statement block inside the for loop will be executed
-- where the offercode and materialNum are inserted into another table 'NEWTABLE'.
-- Remember to create the table NEWTABLE before executing this procedure.
FOR vl AS
SELECT Product.materialNum materialNum
FROM OfferInstance, OfferToProduct, Product
WHERE Product.productId = OfferToProduct.productId
AND OfferToProduct.offerId = OfferInstance.offerId
AND OfferInstance.offerCode = offer_code_in
DO
INSERT INTO NEWTABLE VALUES (offer_code_in, materialNum);
END FOR;
END
@
-------------------------------------------------------------------
Note: I haven't tested it. But believing that it will work.
Please let me know the results.
With Regards,
Jake
Quote:
Originally posted by ShelleyMKG
Thanks again for helping...I got a little closer and posted a different reply..but I tried the execute immediate and here are my results:
create procedure test8 (IN offer_code_in char(6))
begin
Declare condition_TEMP varchar(2048);
declare c1 cursor with return for
SELECT 'select materialnum from product where 'CONCAT REPLACE(CONDITION, 'ProductID','MATERIALNUM')
from offertoproduct
Where offerid =
(select offerid
from offerinstance
where offercode = offer_code_in)
order by condition;
open c1;
Fetch c1 into condition_TEMP;
close c1;
execute immediate condition_TEMP;
end
SQL0084N An EXECUTE IMMEDIATE statement contains a SELECT or
VALUES statement.
Explanation:
A SELECT or VALUES statement was used in an EXECUTE IMMEDIATE
statement.
The statement cannot be processed.
User Response:
The implied function is not supported. Prepare the SELECT or
VALUES statement. Then use OPEN, FETCH, and CLOSE.
sqlcode : -84
sqlstate : 42612
The Condition field can contain "ProductID = '000000000037005088'
or a grouping of ProductId's - "HIGHERLEVEL = '15' AND LOWERLEVEL = 'R3'". I can retrieve more than one or many conditions per offerid also.
|