Is this possible in any way that I apply function on all columns in a SELECT. For example,
SELECT LEN(t.*) FROM Table t;
The problem is that the table is dynamic with dynamic number of columns and I need to apply a function on evry column.
No, you need some dynamic sql;
declare @table varchar(256) = 'the_table'
declare @sql nvarchar(4000) = ''
select
@sql += case @sql when '' then '' else ',' end + ' func(' + quotename(column_name) + ') as ' + quotename(column_name)
from
information_schema.columns
where
table_name = @table
set @sql = 'select' + @sql + ' from ' + @table
exec(@sql)
which produces & executes
select func([fld1]) as [fld1], func([fld2]) as [fld2] ... from the_table
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With