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

See also  Why ChatGPT Is So Important Today
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist