How to create a condition that does not include the month of December?

Posted on

Question :

I’m creating a condition to be run before the month of December, that is, it only runs in the January period of November .

IF (SELECT TarFechamento FROM Tarefa WHERE TarID = @Tarefa) < '01-12-2017'

I put it like it was in the year of 2017 , but I want independent of the year 2018,2019,2020, etc.

Answer :

The query you need to do is this, using month ( ) to know only the month of the date

SELECT * FROM Tarefa WHERE TarID = @Tarefa and month(TarFechamento) <> 12


The easiest way to get (not) just the part of the month from a date in SQL is to just use the DATEPART () function. For more information about the function, just visit the link link.


Leave a Reply

Your email address will not be published. Required fields are marked *