ALTER PROCEDURE "DBA"."SelectWithColumnsOrdered"(in @table_name char(100)) BEGIN declare @sql long varchar ; select list(cname, ', ' order by cname) into @sql from sys.syscolumns where tname = @table_name ; set @sql = 'select ' || @sql || ' from ' || @table_name ; execute immediate with result set on @sql ; END FWIW, with v17, indirect identifiers often help to omit execute immediate calls - however, I don't know whether they could also be of help for cases like this with a variable number of identifiers (here columns)... - just in case someone has an idea...
(23 Aug '22, 08:07)
Volker Barth
|
Will you accept an answer, similar to this one https://stackoverflow.com/a/10498945 where the SQL query will be built at runtime via the stored procedure?
The idea is quite simple, you get all columns from the DB, sort them, create a string and then execute it as an SQL statement.