Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need solution for Query 1

Status
Not open for further replies.

llmclaughlin

Programmer
Aug 20, 2004
140
US
I have three columns in a table called oncall_schedule
Fields

Begin_date End_Date Srm_Id
03/06/2006 03/12/2006 srmllm

What I need to do is select the srm_id where sysdate falls between or equals to the begin_date and end_date.

I've tried and tried, just can not get the one record I'm looking for.

Thanks

Louie


 
Louie,

The first stipulation here is that both BEGIN_DATE and END_DATE are of data type DATE. With that provision, the following should work:
Code:
select * from louie;

BEGIN_DAT END_DATE  SRM_ID
--------- --------- ------
06-MAR-06 12-MAR-06 srmllm
03-MAR-06 05-MAR-06 srmllm

select srm_id from louie
where sysdate between begin_date and end_date;

SRM_ID
----------
srmllm
Let us know if this satisfactory.

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[ Providing low-cost remote Database Admin services]
Click here to join Utah Oracle Users Group on Tek-Tips if you use Oracle in Utah USA.
 

A potential problem will occur if the end date is 9-MAR-06 and today is the 9th. Sysdate contains a time factor. If the end date does not, you may want to try:
Code:
select srm_id
from louie
where trunc(sysdate) between begin_date
                     and     end_date;

Beware of false knowledge; it is more dangerous than ignorance. ~George Bernard Shaw
Consultant Developer/Analyst Oracle, Forms, Reports & PL/SQL (Windows)
My website: Emu Products Plus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top