Free cookie consent management tool by TermsFeed Policy Generator
  • Azure SQL
  •    6 page views
  •   0 video views
  • 2024, March 22, Friday

#054 Conditional per logical function in Azure SQL

Como obter resultado por condicional de função lógica 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. ID], IIF([Dismissal] IS NULL, 'I', 'A') as Status

    :
    • SELECT: Indicates that the next part of the code will specify which columns will be returned in the query.
    • [ID]: Selects the "ID" column.
    • IIF([Resignation] IS NULL, 'I', 'A') AS Status: Uses the IIF function to evaluate whether the "Resignation" column is null. If it is null, it assigns 'I' (indicating "Inactive"), otherwise it assigns 'A' (indicating "Active"). The result of this condition is renamed to "Status".
  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."
  3. ORDER BY [ID] DESC

    :
    • order BY: Sorts the results of the query.
    • [ID] DESC: Sorts the results based on the "ID" column, descending (DESC), i.e. from the highest value to the lowest.
Therefore, the

code returns employee IDs and a status ('I' for Inactive, 'A' for Active) based on the presence or absence of a resignation date in the "Resignation" column. The results are sorted by the IDs in a descending fashion. This query is useful when you want to view the status (active or inactive) of collaborators in descending order of ID.

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

  • Reading time 1 min 15 seg

avatar
Fabio Santos

Data Scientist and Consultant for Digital and Analytics Solutions


  • Share

Youtube Channel

@fabioms

Subscribe now