Only contextualizing the @Rovann response
DATEADD returns a date. The MONTH returns an integer that represents the month of the date.
Soon your clausulá where MONTH(TarVencimento) = DATEADD(MONTH,1,TarData)
does not seem to make sense.
Your where
clause becomes more meaningful, changing it to MONTH(TarVencimento) = MONTH(DATEADD(MONTH,1,TarData))
. Where you add 1 month to the TarData
field, take the month and finally compare it to the TarVencimento
month.
Seeing your question, I see that I stopped in time with SQL Server studies, because I still use # to get the month in the date fields, getting something like: DATEPART(MONTH, TarVencimento) = DATEPART(MONTH, DATEADD(MONTH,1,TarData))
, which is not unsatisfactory either, since DATEPART returns an integer that represents the datepart of the specified date.