dbTalk Databases Forums  

sql returns dates less then asked for

comp.database.oracle comp.database.oracle


Discuss sql returns dates less then asked for in the comp.database.oracle forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
jeffchirco@gmail.com
 
Posts: n/a

Default sql returns dates less then asked for - 03-18-2005 , 10:23 AM






sql returns dates less then asked for

I have a query that is supposed to return records greater than a
certain date, but it is returning records that are way less than the
date in the query. I don't understand why. I have just found out that
if you remove the OR statment it works fine. I don't get it, please
shed some light here. Here is the query.
Thanks.

select
dbwonum, dbopendate,dbstorenum
from workorder
where dbtype = 201
or dbtype = 236
and dbopendate >= '1/1/2004'
order by dbopendate asc;

Here is a describe on the table
DBWONUM NOT NULL NUMBER(11)
DBSTORENUM NOT NULL NUMBER(4)
DBSUMMARY VARCHAR2(255)
DBTYPE NOT NULL NUMBER(11)
DBASSID NUMBER(6)
DBRECEIVEDBY NOT NULL NUMBER(7)
DBRESPONSIBLE NOT NULL NUMBER(7)
DBSTATUS NOT NULL NUMBER(3)
DBFOLLOWTYPE NOT NULL NUMBER(2)
DBOPENDATE NOT NULL DATE
DBDUEDATE NOT NULL DATE
DBCLOSEDATE DATE
DBDESKDESC CLOB
DBDESKRESLTN CLOB
DBTECHDESC CLOB
DBTECHRESLTN CLOB
DBREPEATCALL NOT NULL NUMBER(1)
DBFOLLOWDATE DATE
DBNOTES VARCHAR2(20)
DBSUPERID NUMBER(6)
DBLASTMOD VARCHAR2(25)
DBAFTERHOUR NOT NULL NUMBER(1)


Reply With Quote
  #2  
Old   
Eric de Redelijkheid
 
Posts: n/a

Default Re: sql returns dates less then asked for - 03-20-2005 , 06:37 AM






Anno Domini 18-3-2005 17:23, jeffchirco (AT) gmail (DOT) com sprak aldus:

Quote:
sql returns dates less then asked for

I have a query that is supposed to return records greater than a
certain date, but it is returning records that are way less than the
date in the query. I don't understand why. I have just found out that
if you remove the OR statment it works fine. I don't get it, please
shed some light here. Here is the query.
Thanks.

select
dbwonum, dbopendate,dbstorenum
from workorder
where dbtype = 201
or dbtype = 236
and dbopendate >= '1/1/2004'
order by dbopendate asc;


It might be a conversion problem

try

select
dbwonum, dbopendate,dbstorenum
from workorder
where dbtype in (201,236)
and dbopendate >=to_date('01-JAN-2004','DD-MM-YYYY')
order by dbopendate asc;

It would depend on what you mean: do you want rows where dbtype = 201 and 236 where the date condition applies to both dbtype values or does the date condition apply only to dbtype 236. In that case I think you should use brackets in your where clause.

for example:
select
dbwonum, dbopendate,dbstorenum
from workorder
where dbtype = 201
or (dbtype=236 and dbopendate >=to_date('01-JAN-2004','DD-MM-YYYY'))
order by dbopendate asc;



Quote:
Here is a describe on the table
DBWONUM NOT NULL NUMBER(11)
DBSTORENUM NOT NULL NUMBER(4)
DBSUMMARY VARCHAR2(255)
DBTYPE NOT NULL NUMBER(11)
DBASSID NUMBER(6)
DBRECEIVEDBY NOT NULL NUMBER(7)
DBRESPONSIBLE NOT NULL NUMBER(7)
DBSTATUS NOT NULL NUMBER(3)
DBFOLLOWTYPE NOT NULL NUMBER(2)
DBOPENDATE NOT NULL DATE
DBDUEDATE NOT NULL DATE
DBCLOSEDATE DATE
DBDESKDESC CLOB
DBDESKRESLTN CLOB
DBTECHDESC CLOB
DBTECHRESLTN CLOB
DBREPEATCALL NOT NULL NUMBER(1)
DBFOLLOWDATE DATE
DBNOTES VARCHAR2(20)
DBSUPERID NUMBER(6)
DBLASTMOD VARCHAR2(25)
DBAFTERHOUR NOT NULL NUMBER(1)




Reply With Quote
  #3  
Old   
jeffchirco@gmail.com
 
Posts: n/a

Default Re: sql returns dates less then asked for - 03-22-2005 , 09:43 PM



I got it figured out. Thanks. I did not have the ( ) in the correct
places.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.