Delete period without tag Between

Asked

Viewed 30 times

-1

Good afternoon,

Is there any way to delete a period without using the BETWEEN?

    x NOT BETWEEN HorFim AND HorIni   
and y NOT BETWEEN HorFim AND HorIni

Where:

x = hora inicial digita pelo usuario.
y = hora final digita pelo usuario.

I have to make this sql work without BETWEEN, the problem is that my final hour(HorFim) and less than the initial time(HorIni)

  • How the columns are declared x and y? The correct answer depends on this information... // No BETWEEN?! Could you explain why?

  • Has any response helped solve the problem and can address similar questions from other users? If so, make sure to mark the answer as accepted. To do this just click on the left side of it (below the indicator of up and down votes).

1 answer

1

Transform the DATETIME in DATE to remove the time and use the operators maior que and menor que:

SELECT *
  FROM tabela
 WHERE (CAST(x AS DATE) < CAST(HorIni AS DATE) OR CAST(x AS DATE) > CAST(HorFim AS DATE))
   AND (CAST(y AS DATE) < CAST(HorIni AS DATE) OR CAST(y AS DATE) > CAST(HorFim AS DATE))

I also noticed that the order of your BETWEEN was reversed. The above condition can be changed to:

SELECT *
  FROM tabela
 WHERE CAST(x AS DATE) NOT BETWEEN CAST(HorIni AS DATE) AND CAST(HorFim AS DATE))
   AND CAST(y AS DATE) NOT BETWEEN CAST(HorIni AS DATE) AND CAST(HorFim AS DATE))
  • The person responsible for downvote can you report the error in the answer? Only -1 without explanation is useless.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.