sql – Select Alias

Question:

I'm trying to establish a select to be an alias of a record. I still don't know if there is this possibility, could someone clarify this question for me?

ex: select 1 as (select dia_da_semana from ano where dia = 1 and mes = 10)

Above example more or less what my idea would be.

Answer:

What you want can be solved using dynamic SQL:

DECLARE @SQL NVARCHAR(1000)

SET @SQL = 'SELECT 1 AS ''' + (SELECT dia_da_semana FROM ano WHERE dia = 1 AND mes = 10) + ''''

EXEC(@SQL)
Scroll to Top