If you're going to construct a list in a variable, you could use INLIST():
LOCAL aStateArray[1],cBadStateWhereCond,nCtr
SELECT '"'+BadState+'"' FROM bad_st INTO ARRAY aStateArray
cBadStateWhereCond = IIF(_TALLY > 0, '!INLIST(State,' + aStateArray[1],
".T.")
FOR nCtr = 2 TO _TALLY
cBadStateWhereCond = cBadStateWhereCond + ',' + aStateArray[nCtr]
ENDFOR
IF cBadStateWhereCond) # ".T."
cBadStateWhereCond = cBadStateWhereCond + ")"
ENDIF
RELEASE aStateArray, nCtr
SELECT * FROM x WHERE &cBadStateWhereCond
>
>I have a very intenstive app that has 100,000 records
>that need to be evaluated one at a time for 25 different
>conditions.
>
>One of the conditions is to check and see if any of 4
>state codes are contained within a field of the record.
>I want a data driven solutoin since the states can expand
>and contract. I can NOT do a simple SELECT * FROM
>x where z NOT IN (sub select).
>
>What is the fastest non-hard coded way to perform this
>type of query? The data in the bad_st table will be constant
>for the duration of the program if that helps. I was considering
>creating a character variable that is a comma separated
>list.
>
>What are your thoughts?
>
Attachment Converted: Edward M Rauh.vcf