Free cookie consent management tool by TermsFeed Policy Generator
  • Azure SQL
  •    9 page views
  •   0 video views
  • 2024, June 21, Friday

#019 Get Months Difference Between Dates in Azure SQL

Como obter diferença de meses entre datas 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" with a specific condition. I'll explain each

part of the code:SELECT [
  1. Collaborator], DATEDIFF(MONTH, [Admission], [Dismissal]) THE MONTHS

    :
    • SELECT: Indicates that the next part of the code will specify which columns will be returned in the query.
    • [Contributor]: Select the "Contributor" column.
    • DATEDIFF
    • (MONTH, [Admission], [Resignation]) AS MONTHS: Uses the DATEDIFF function to calculate the difference in months between the "Admission" and "Resignation" columns. The result is renamed "MONTHS".
  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. WHERE
  4. Dismissal IS NOT NULL:WHERE

    • : Filters results based on a condition.
    • Dismissal IS NOT NULL: The condition specifies that only records whose value in the "Dismissal" column is not null will be included in the query. In other words, the query returns only employees who have been laid off.

Therefore, the code returns the employee's name ("Employee") and the difference in months between the date of admission ("Admission") and the date of dismissal ("Resignation") for employees who have been terminated. This query is useful when you want to calculate the length of service in months for laid-off employees.

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

  • Reading time 1 min 13 seg

avatar
Fabio Santos

Data Scientist and Consultant for Digital and Analytics Solutions


  • Share

Youtube Channel

@fabioms

Subscribe now