Solved

How can I query rows using a date field properly?

Posted on 2008-06-26
3
242 Views
Last Modified: 2013-12-19
Hi,
This is my line of code (which doesn't work), how can this modified to retrieve rows?

AND CBPV.BP_START_DATE >= to_date(:bp_period_start,'DD/MM/YYYY')
AND CBPV.BP_START_DATE <= to_date(:bp_period_end,'DD/MM/YYYY')

bp_start_date is a date field type, sample data
6/1/2008 , 4/23/2008

Thanks,
R
0
Comment
Question by:Rhonda Carroll
3 Comments
 

Expert Comment

by:Dranth
Comment Utility
Make sure the values used for the parameters are strings and not date.

0
 
LVL 44

Expert Comment

by:Arthur_Wood
Comment Utility
is the field  CBPV.BP_START_DATE a DATE type field, or a Varchar field?

you might try this (if CBVP.BP_START_DATE is a DATE field):

AND TO_CHAR(CBPV.BP_START_DATE, 'YYYYMMDD') >= to_char(:bp_period_start,'YYYYMMDD')
AND TO_CHAR(CBPV.BP_START_DATE, 'YYYYMMDD') <= to_char(:bp_period_end,'YYYYMMDD')


AW


0
 
LVL 10

Accepted Solution

by:
dbmullen earned 125 total points
Comment Utility
a date is a date is a date, regardless of how you display it.  it's saved as a DATE

declare
bp_period_start date := to_date('20080101','yyyymmdd');
bp_period_end date := trunc(sysdate);
begin
...

select *
from ...
where ...
AND CBPV.BP_START_DATE >= :bp_period_start
AND CBPV.BP_START_DATE <= :bp_period_end
...
;
end;
/
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now