Q:

Generate column Alias name dynamically in MS SQL Server

How to Generate column Alias name dynamically in MS SQL Server, Please advise on the same. Thank you.
I need to out a value from sp with the alias name which is coming through one input parameter on the same sp.

A:

create procedure my_procedure (@col_alias varchar(100))
as
    declare @my_stmt nvarchar(max) = N'select 1+1 as ' + @col_alias
    exec sp_executesql @stmt = @my_stmt

exec my_procedure @col_alias = '[This is a dynamix col alias]'

This is a dynamix col alias
---------------------------
2

