devxlogo

Choosing a Column Depending on Procedure Argument

Choosing a Column Depending on Procedure Argument

Question:
Can I specify the column I want to select from as an argument to the procedure? Something like:

create procedure show_product(language char(2), ID integer) returning char(255);define p_prod_name CHAR (255);select language INTO p_prod_name from productnames where prod_id = ID;return p_prod_name;END PROCEDURE

The table productnames would then contain a column for each countrycode and, depending on the argument I pass to the procedure, I would get the name of the product in the correct language. (I am running IDS 7.3 on Linux.)

Answer:
Sure, that’s done all the time. Another way would be to create a stored procedure with a series of IF statements. Look at the following pseudocode:

IF passed_in = "ENGLISH" then    SELECT english_name from table where ID = blahIF passed_in = "DEUTSCH" then   SELECT german_name from table where ID = blah

devx-admin

Share the Post: