Select to Alias

Asked

Viewed 74 times

3

I’m trying to establish a select to be a alias of a record. I do not know yet if there is such a possibility, could someone clarify me this doubt?

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

Example of more or less how my idea would be.

2 answers

0

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)
  • This way it is necessary to do through a function or Procedure?

0

In postgresql the alias 'and in this format:

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

but would probably return you an error if you have more than one value, pq would be a subquery, if you want in Voce array format you can do so:

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

example: https://www.db-fiddle.com/f/vBmaYMc6AZPkvuGimCogad/1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.