Yes, but since the question was about optimization: this might be fairly slow. I think execution might faster if you create a single variable with all the conditions - a little detail work, but not really difficult - and then use macro substitution in your SQL - SELECT command.
>Hi Hilmar,
>
>I know that combining a variable number of ANDs can be tricky for filters, that's why I asked Franco about the possibility to use a cursor in stead. I discovered some years ago that you can SELECT from a cursor with the same name as your result cursor, which makes this very easy for cursors, given ALL the different conditions are ANDs:
>*laCondition is an array of condition, each element is ONE legal condition, for instance "Department=1"
>lcCondition=laCondition(1)
>SELECT * FROM yourTable where &lcCondition INTO CURSOR yourResult ReadWrite
>FOR x=2 to ALEN(laCondition)
> lcCondition=laCondition(x)
> SELECT * FROM yourResult where &lcCondition INTO CURSOR yourResult ReadWrite
>ENDFOR
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)