Free cookie consent management tool by TermsFeed Policy Generator
  • Azure SQL
  •    2 page views
  • 2024, May 08, Wednesday

#053 Combine column values with separator in Azure SQL

Como combinar valores de colunas com separador em Consulta (SELECT) existente na linguagem de Manipulação de Dados (DML) do Azure SQL/SQL Server

This T-SQL code performs a query on the "erp. Collaborators". I'll explain each part

of the code:SELECT
  1. CONCAT_WS(', ', [Address], [City], [State]) AS ADDRESS

    :
    • SELECT: Indicates that the next part of the code will specify which columns will be returned in the query.
    • CONCAT_WS(', ', [Address], [City
    • ], [State]) AS ADDRESS: Uses the CONCAT_WS function to concatenate the "Address", "City" and "State" columns with a comma followed by a space as a separator. The result of this concatenation is renamed "ADDRESS".
  2. FROM [erp].[ Collaborators]

    :
    • FROM: Indicates the table from which the data will be selected.
    • [erp]. [Collaborators]: This is the name of the table from which the data will be extracted. The prefix "erp." suggests that the table is in a schema called "erp."

Therefore, the code returns a single column called "ADDRESS", which is the result of concatenating the "Address", "City", and "State" columns of the "erp. Collaborators". Each value in this column is a string that represents the employee's full address, where the parts of the address are separated by a comma and a space. This technique is useful for consolidating multiple columns of text into a single column for easy viewing or use in reports.

This content contains
  • Content Imagem
  • Language Portuguese
  • Duration
  • Subtitles Não

  • Reading time 1 min 8 seg

avatar
Fabio Santos

Data Scientist and Consultant for Digital and Analytics Solutions


  • Share

Youtube Channel

@fabioms

Subscribe now