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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Help 1

Status
Not open for further replies.

dbomrrsm

Programmer
Feb 20, 2004
1,709
GB
I have a table (tableA) that holds a date field and I want everything from tableA where the date field is greater that the maximum date selected from a different table tableB.

The difficulty I have is that tableA's date field is a date data type and the field from tableB is a varchar2 (23).

Example data from tableA

select max(date_field) from tableA - 13/12/2006 14:37:15

select date_field from tableB - 2006-12-11 16:55:51.000

How do I write the below query:
Code:
select *
from tableA
where date_field > 
(select date_field from tableB)

BTW tableB only has one row so the select only returns one value.

I have TO_CHAR'ed and TO_DATE'd both fields to death and cant get it to work.

TIA

[bandito] [blue]DBomrrsm[/blue] [bandito]

[blue]Software code, like laws and sausages, should never be examined in production[/blue][black] - [/black][purple]Edward Tenner[/purple]
 
select *
from tableA
where date_field >
(select to_date(date_field, 'YYYY-MM-DD HH24:MI:SS') from tableB)
 
Dagon

Thanks but your code produces error:

ORA-01830: date format picture ends before converting entire input string


[bandito] [blue]DBomrrsm[/blue] [bandito]

[blue]Software code, like laws and sausages, should never be examined in production[/blue][black] - [/black][purple]Edward Tenner[/purple]
 
Dagon

Thanks - got it by doing:
Code:
select *
from tableA
where date_field > 
(select to_date(substr(date_field,1,19), 'YYYY-MM-DD HH24:MI:SS') from tableB)

Cutting off the milliseconds in the varchar2 field.



[bandito] [blue]DBomrrsm[/blue] [bandito]

[blue]Software code, like laws and sausages, should never be examined in production[/blue][black] - [/black][purple]Edward Tenner[/purple]
 
Unless there is only one row in tableb, you are not using the max date. Use

select *
from tableA
where date_field >
(select max(to_date(substr(date_field,1,19), 'YYYY-MM-DD HH24:MI:SS')) from tableB);

Bill
Oracle DBA/Developer
New York State, USA
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top