Trunc Hibernate

Asked

Viewed 57 times

0

I have the following query that I need to search in the database for schedules according to the dates reported (initial date and final date). Let’s say I made an appointment for the 20th/10th/19th. If I try to get this schedule by informing the day 20/10/19 in the two conditions, initial date and final date, it brings me nothing and the schedule exists. If I try to search stating as initial date the day 19/10/19 and as final date the scheduling date that is day 20/10/19, it brings me saved scheduling, so far so good but also need to bring the scheduling informing the same date in both conditions. What’s missing or wrong?

        <![CDATA[
            select 
                da.dtAgenda as dtAgenda, 
                to_char(da.dtAgenda, 'DD/MM/YYYY') as dsDataFormatada, 
                da.agendaDonoAgenda.donoAgenda.dsDonoAgenda as dsDonoAgenda,
                da.agendaDonoAgenda.agenda.dsAgenda as dsAgenda,
                da.agendaDonoAgenda.agenda.cdAgenda as cdAgendaSelecionado,
                da.agendaDonoAgenda.donoAgenda.cdDonoAgenda as cdDonoAgendaSelecionado
            from  
                DistribuicaoAgendaModel as da
            where 
                da.agendaDonoAgenda.agenda.cdAgenda = :cdAgenda
                and da.agendaDonoAgenda.agenda.idAtivo = 'S'
                and da.agendaDonoAgenda.agenda.entidade.cdEntidade = :cdEntidade
                and trunc(da.dtAgenda) between :dtInicial and :dtFinal
            group by
                da.dtAgenda, 
                da.agendaDonoAgenda.agenda.dsAgenda,
                da.agendaDonoAgenda.donoAgenda.dsDonoAgenda,
                da.agendaDonoAgenda.agenda.cdAgenda,
                da.agendaDonoAgenda.donoAgenda.cdDonoAgenda
            order by 
                da.dtAgenda, 
                da.agendaDonoAgenda.donoAgenda.dsDonoAgenda             
        ]]>
    </query>

1 answer

0


You can add equal conditions for start date and end date:

and ( 
   (trunc(da.dtAgenda) between :dtInicial and :dtFinal) OR
   trunc(da.dtAgenda) = :dtInicial OR 
   trunc(da.dtAgenda) = :dtFinal
)

Browser other questions tagged

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