Thanks again Vaibhav !
Yes. I think I got your point while using Dynamic column names and here is the code below, i tried and executed and observed the difference between EXEC and EXECUTE IMMEDIATE.
--Creating a table
CREATETABLE tab (id int,name nvarchar(20),age integer);
--inserting data into table
insertinto tab values(30,'abc',15);
insertinto tab values(20,'xyz',17);
insertinto tab values(15,'pqr',16);
--creating procedure to perform dynamic sql
CREATEPROCEDURE proc_dynamic_result2(in col1 varchar(20),in col2 varchar(20)) AS
BEGIN
EXECUTEIMMEDIATE'SELECT ' || :col1 || ','|| :col2 ||' FROM tab ';
END;
--calling procedure
call proc_dynamic_result2('name','id');
callproc_dynamic_result2('id','age');
callproc_dynamic_result2('name','age');
Note: Result is displayed in procedures result iterator, but when I ran with just EXEC result was not displayed in the procedures result iterator .
Thanks,
Sree