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

#055 Choose value from a list in Azure SQL

Como escolher valor de uma lista 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 [ID], CHOOSE([ID_Motivo_Demissao], 'WITH cause', '
  1. WITHOUT cause', NULL, 'Resignation') AS [Motivo_Demissao]

    :
    • SELECT: Indicates that the next part of the code will specify which columns will be returned in the query.
    • [ID]: Selects the "ID" column.
    • CHOOSE([ID_Motivo_Demissao
    • ], 'WITH Cause', 'WITHOUT Cause', NULL, 'Resignation') AS [Motivo_Demissao]: Uses the CHOOSE function to assign a reason for resignation based on the value of the "ID_Motivo_Demissao" column. The CHOOSE function allows you to choose a value based on a list of options. If the value is 1, it will be 'WITH just cause'; if it is 2, it will be 'without cause'; if it's 3, it's NULL; if it's 4, it will be 'Resignation'. The result of this choice is renamed "Motivo_Demissao".
  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 the employee IDs and the corresponding reason for resignation based on the value of the "ID_Motivo_Demissao" column. This query is useful when you want to map resignation reason codes to more readable descriptions in your results.

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

  • Reading time 1 min 12 seg

avatar
Fabio Santos

Data Scientist and Consultant for Digital and Analytics Solutions


  • Share

Youtube Channel

@fabioms

Subscribe now