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!

set filter to

Status
Not open for further replies.

newfree

Programmer
Sep 21, 2011
3
US


SET FILTER TO D_CALL => BDATE .AND. D_CALL =< EDATe .and. account="2331".AND.account ="3730" &&**.

Simple question.. can you call a filter to do two different multiple things like filter date and several "account". The date search works fine when accounts are removed. The accounts work fine when the date is removed. With date and one account it works perfect. With date and multiple accounts nothing comes up. I have tried plugging in .and. and .or. Or gives me all the accounts I want but returns records from all dates.
Paul
 
Paul,

No, it can't work.

You have this:

account="2331".AND.account ="3730"

But Account can't be equal to one thing AND another.

You need OR rather than AND. And you might need parenthesis around it, depending on exactly what you want to achieve.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
You can do any expressions, but it makes no sense to check account being 2331 and 3730 at the same time, an account can either be one or the other but not both at the same time.

Also check date order of bdate and edate, d_call can only be between those two dates, if bdate<edate.

Also be aware of problmes when using variables in SET FILTER expressions, if variables go out of scope, when the method including the SET FILTER ends, the FILTER is still active and cannot evaluate expressions with undeclared variables.

I'd recommend using SQL and WHERE clause instead of filter, or LOCATE FOR in conjunction with CONTINUE or SCAN FOR..ENDSCAN, whatever suits best as a replacement of SET FILTER for you.

Bye, Olaf.
 
Thanks for your great resoponses I will explore those options. What I am trying to acheive is to filter for a list of several specific accounts within a date range.
Paul
 
Paul,

You say you want to filter on some specific accounts. One way to do that is with INLIST():

Code:
SET FILTER TO D_CALL => BDATE .AND. D_CALL =< EDATe .and. ;
  INLIST(account, "2331", "3730", "34567", "76543")

You can further simplify it like this:

Code:
SET FILTER TO BETWEEN(D_CALL, BDATE, EDATe) .and. ;
  INLIST(account, "2331", "3730", "34567", "76543")

If I've understood it right, that should do what you want.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
All of the above is good advice.

Another way to get what you need would be with a SQL Query and, depending on how big the table is, it might be faster.

Code:
SELECT *;
   FROM MyTable;
   WHERE BETWEEN(D_CALL, BDATE, EDATe);
   AND INLIST(account, "2331", "3730", "34567", "76543");
   INTO CURSOR Results READWRITE
or
Code:
* --- Create List Of Acct Numbers ---
cAcctList = "2331,3730,34567,76543"  && Create Statically or Dynamically
* --- Run Query ---
SELECT *;
   FROM MyTable;
   WHERE BETWEEN(D_CALL, BDATE, EDATe);
   AND (ALLTRIM(account) + ',') $ cAcctList;
   INTO CURSOR Results READWRITE

Good Luck,
JRB-Bldr
 
I do not know where you guys come from but you are all geniuses in my book.
Thank you very much
Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top