Date Subtraction and return positive SQL value

Asked

Viewed 52 times

0

Good afternoon, I’m trying to build a Query in which I subtract two dates to return the value in days, but I only need the days that returned positive, I ran the Query that I assembled but had no return

DECLARE @POSITIVO INT

SELECT @POSITIVO = DATEDIFF(DAY, Contas_Receber.PagamentoData, Contas_Receber.Vencimento) from Contas_Receber WHERE @POSITIVO > 0

Give me the result of successfully completed Commands.

1 answer

0


To know if the result will be positive the second date must be greater than the first:

SELECT DATEDIFF(DAY, cr.PagamentoData, cr.Vencimento)
  FROM Contas_Receber cr
 WHERE cr.vencimento > cr.pagamentodata
  • 1

    Man, thanks, it worked perfectly.

Browser other questions tagged

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