Skip to content
Advertisement

SQL create extra column which gets data from the table two columns

I have a query which have two fields that I would like to combine as a new column. On excel it goes something like this

But I don’t know how to create this formula on sql that the output would be like

NEW ID = 88201911 aka 88=companyID 2019=year 11=month

Example code

Advertisement

Answer

You cannot re-use a column alias in the same select. So you need to repeat the expressions:

In addition, never use single quotes to refer to columns. They should only be used for string and date constants.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement