DATE(of a datetime field) . Did I lost the advantage of DT f

Posted by OctavioOlguin on 30-Apr-2015 12:43

I have a table that eventually will hold bunchs of records.

Table dwBunch
field BranchNmbr as integer
FIELD FECHA AS DATETIME
field qty as decimal
field foo as char.... etc
INDEX ON FECHA
(and some more index)

Table has index on date-time field.   One process i'm developing, sumarizes the records by date.  I need the last batch of records that day from every branch.. as that day may contain several batchs of records with same date (but time) for each branch warehouse, they are diferent from batch one hour earlier. So I came to this:

FOR EACH dwBunch    
WHERE DATE(fecha) = ParameterDate:
....
END;.

I wonder, did I lost the advantage on the index to restrict the scan of all records, or otherwise database will bracket on other index and make some inefficient selection..

PS. I came to an algorithm I learned right here to preselect the records for every branch that are the newest according to datetime, and the query again the table, now knowing the datetime of interest.for each branch....

All Replies

Posted by Tim Kuehn on 30-Apr-2015 12:51

Yes - functions like this:

EACH TableName
   WHERE function(TableName.FieldName) = something

will do a table scan _except_ for functions like ROWID(TableName) and RECID(TableName).

This happens because there's no way for the db engine to do a straight match between the equation and what's in the table.

To do an equivalent-to-DATE matching on a DATETIME field and get the index bracketing, do this:

EACH TableName
WHERE TableName.DateTime >= DateTime(dtVariable, 0) AND 
TableName.DateTime < DateTime(dtVariable + 1, 0)


Posted by OctavioOlguin on 30-Apr-2015 13:40

I knew it....

And that bracketing tip is cool!!!  I'll do as sugested.  Thanks!!!!

pS. how do you format the code? (with number and stuff)

Posted by Peter Judge on 30-Apr-2015 13:43

There's an option to use the rich editor, and then there's an option to ad syntax highlighting.
 
[collapse]
From: OctavioOlguin [mailto:bounce-OctavioOlguin@community.progress.com]
Sent: Thursday, 30 April, 2015 14:41
To: TU.OE.Development@community.progress.com
Subject: RE: [Technical Users - OE Development] DATE(of a datetime field) . Did I lost the advantage of DT field?
 
Reply by OctavioOlguin

I knew it....

And that bracketing tip is cool!!!  I'll do as sugested.  Thanks!!!!

pS. how do you format the code? (with number and stuff)

Stop receiving emails on this subject.

Flag this post as spam/abuse.

[/collapse]

Posted by OctavioOlguin on 30-Apr-2015 14:09

do:
thank =  "you".
a().
lot().
end.

Posted by Brian K. Maher on 30-Apr-2015 14:19

 
** Unknown Field or Variable name - thank. (201)
**  Could not understand line 2. (196)
 
Couldn't resist the temptation.  </smile>
 
 
 
[collapse]
From: OctavioOlguin [mailto:bounce-OctavioOlguin@community.progress.com]
Sent: Thursday, April 30, 2015 3:10 PM
To: TU.OE.Development@community.progress.com
Subject: RE: [Technical Users - OE Development] DATE(of a datetime field) . Did I lost the advantage of DT field?
 
Reply by OctavioOlguin
do:
thank =  "you".
a().
lot().
end.
Stop receiving emails on this subject.

Flag this post as spam/abuse.

[/collapse]

Posted by OctavioOlguin on 30-Apr-2015 15:14

do:
   Tim:("Thanks").
   Peter:("Tanks").
   Brian:("Jajaja").
   Neither:("Do I").
end.




i   Sintax check: OK


Press scape and get to work

This thread is closed