Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread Is there a better way to do this filter?
Sat, Apr 12 2014 11:38 AMPermanent Link

kamran

Hi Just not getting what I need from the below code.

I have two indexes: product_promotion_end_start_date, product_promotion_end_date.
so a product would have the respective dates filled in so as to provide a range for a current promotion based on dates.

I need to select the products that are in range based on the database stored values
e.g. just show products with a start promotion date of 01/01/2014
and an end promotion date of 31/12/2014.

My Code:

DataFrm.tbProduct.IndexFieldNames := PRODUCT_PROMOTION_START_DATE;PRODUCT_PROMOTION_END_DATE';
DataFrm.tbProduct.SetRangeStart;
DataFrm.tbProduct.FieldByName('PRODUCT_PROMOTION_START_DATE').AsDateTime := StrToDate('01/01/2014');
DataFrm.tbProduct.SetRangeEnd;
DataFrm.tbProduct.FieldByName('PRODUCT_PROMOTION_END_DATE').AsDateTime := StrToDate('31/12/2014');
DataFrm.tbProduct.ApplyRange;

Any thoughts !

Regards

Kamran
Sat, Apr 12 2014 5:18 PMPermanent Link

Raul

Team Elevate Team Elevate

<<
kamran wrote:

I have two indexes: product_promotion_end_start_date, product_promotion_end_date.
so a product would have the respective dates filled in so as to provide a range for a current promotion based on dates.

I need to select the products that are in range based on the database stored values
e.g. just show products with a start promotion date of 01/01/2014
and an end promotion date of 31/12/2014.

My Code:

DataFrm.tbProduct.IndexFieldNames := PRODUCT_PROMOTION_START_DATE;PRODUCT_PROMOTION_END_DATE';
DataFrm.tbProduct.SetRangeStart;
DataFrm.tbProduct.FieldByName('PRODUCT_PROMOTION_START_DATE').AsDateTime := StrToDate('01/01/2014');
DataFrm.tbProduct.SetRangeEnd;
DataFrm.tbProduct.FieldByName('PRODUCT_PROMOTION_END_DATE').AsDateTime := StrToDate('31/12/2014');
DataFrm.tbProduct.ApplyRange;

Any thoughts !

>>


I would actually create a single index that includes the 2 date fields.

Haven't used ranges in a while but i think it relied on a single index.

You can continue to assign fields to IndexFieldNames or in that case you assign the new index to the IndexName

Raul
Sat, Apr 12 2014 5:37 PMPermanent Link

Fernando Dias

Team Elevate Team Elevate

Kamran,

It seems you are not understanding how ranges work - you can't set a range using 2 indexes.
You can select the records you want using a Filter instead of a range.
Like this:

DataFrm.tbProduct.IndexFieldNames := 'PRODUCT_PROMOTION_START_DATE' ;
DataFrm.tbProduct.Filter := 'PRODUCT_PROMOTION_START_DATE = ''2014-01-01'' AND PRODUCT_PROMOTION_END_DATE = ''2014-12-31'' ' ;
DataFrm.tbProduct.Filtered := True ;


--
Fernando Dias
[Team Elevate]
Sun, Apr 13 2014 2:50 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

kamran


Back when I was using DBISAM I very rarely used ranges, I generally used filters. Try that.

Roy Lambert
Image