Select entries between two dates

Asked

Viewed 37 times

2

Good, I have a view " Gp_vw_cons_faults " that contains the initial and final date of when a client is missing.

I want to collect all the records of a particular client in a given period of time.

I am trying to use the following query:

select *
    from GP_Vw_Cons_Faltas 
    where DataInicio > "01/01/2015" AND DataFim < "01/10/2016" AND Codigo = 65

That does not return me all the values corresponding to the interval, someone has a solution?

SGBD : Sybase

View columns:

Dating Date Code

  • You did not inform the SGBD nor the data you have in the table

  • I did it now, thank you

  • How the Start and End columns are declared?

3 answers

2


Marco, good morning!

Looking at your problem, the next question came to mind:

There exists within the framework in which the database tools were built the question that differentiates DATA from DATETIME.

Date is the value of the day, example: 01/01/2019 Datetime is the value of the day and hour/minute/second, i.e., a fraction of the time

If Sybase understands the field as datetime in the comparison, it should compare to hour/minute/second, this generates some problems to beat values. I suggest casting/Convert for a date pattern before making the comparison for test effect.

PS: I had this same problem in MSSQL

  • That’s exactly what it was, thank you very much!

  • Imagine, it’s an Issue that date fields always carry.

1

Type the command by passing the dates using the BETWEEN:

select *
from GP_Vw_Cons_Faltas 
where DataInicio BETWEEN '01/01/2015' AND '01/10/2016';

  • I have two columns, it doesn’t work

0

Do you have 2 date columns? One Start Date and another End Date? If yes it has to be so :

select *
from GP_Vw_Cons_Faltas
WHERE `DataInicio` > '2019/03/14' and `DataFim` < '2019/03/14'
AND Codigo = 65

If there’s only one

select *
from GP_Vw_Cons_Faltas
WHERE `data` BETWEEN '2019/03/14' AND '2019/03/14'
AND Codigo = 65

  • It doesn’t work, it doesn’t give me all the values between the intervals. Yes, I have two columns

Browser other questions tagged

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