Home » SQL & PL/SQL » SQL & PL/SQL » SQL Date Select for a range
SQL Date Select for a range [message #19861] Mon, 15 April 2002 01:44 Go to next message
Joe Reed
Messages: 1
Registered: April 2002
Junior Member
Suppose I have 6 variables: day1 , day2 , month1 , month2, year1, year2.
How do I pass these variables into a select statement where I am selecting a row out of a log which occurs between the first date1(day1, month1, year1) and a second date2(day2, month2, Year2). Could you provide something which I could cut and Pastw into SQL WorkSheet and run including the variable declarations.

Thanks from SQL Newbie!!!
Re: SQL Date Select for a range [message #19867 is a reply to message #19861] Mon, 15 April 2002 06:21 Go to previous message
sridhar
Messages: 119
Registered: December 2001
Senior Member
Declare
CURSOR c1 is SELECT * FROM table_name;
v_Rec c1%ROWTYPE;
day1 NUMBER;
.. other variables
Begin
..assign values to your date1....year2 variables

SELECT * from table_name INTO v_Rec
WHERE to_char(date_column, 'dd, mm, yyyy') between
day1 ||','||month1 ||',' || year1
AND day2 ||','||month2 ||',' || year2;

....

End;

Note: format the year in to_char() depending on your variable year1/year2 value. If it is four digits like 2002, then the above statement works.

Thanks,
Sri
Previous Topic: escape ' char
Next Topic: SET NUMWIDTH in FUNCTION or PROCEDURE
Goto Forum:
  


Current Time: Wed Apr 24 11:46:52 CDT 2024