SQL query - Datas Invoice



  • Galera, good afternoon! I'm having a hard time consulting down. I want you to bring all the tasks only when the salary (lack field) is equal to the month after the opening date (tardata). But nothing came in the consultation.

    select * 
    from Tarefa 
    where TarID = 173151 
        and MONTH(TarVencimento) = DATEADD(MONTH,1,TarData)
    


  • Only by contextualizing the @Rovann response

    O https://docs.microsoft.com/pt-br/sql/t-sql/functions/dateadd-transact-sql returns a date. O https://docs.microsoft.com/pt-br/sql/t-sql/functions/month-transact-sql returns an integer representing the month of the date.

    Soon your clausulá where MONTH(TarVencimento) = DATEADD(MONTH,1,TarData) doesn't seem to make sense.

    Make more sense your clausulá where, changing her to MONTH(TarVencimento) = MONTH(DATEADD(MONTH,1,TarData)). Where you add 1 month to the field TarData, take the month and last compare with the month of TarVencimento.

    Seeing your question, I see that I stopped in time with the studies of SQL Server, because I still use https://docs.microsoft.com/pt-br/sql/t-sql/functions/datepart-transact-sql to catch the month in the dates fields, getting something like: DATEPART(MONTH, TarVencimento) = DATEPART(MONTH, DATEADD(MONTH,1,TarData)), which does not cease to be right too, because https://docs.microsoft.com/pt-br/sql/t-sql/functions/datepart-transact-sql returns an integer representing the datepart of the specified date.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2