>Hello everyone,
>I would like to know how to pass a parameter to a view's "where" clause for conditions. For example, in different areas I may have different "where" clause conditions. In one instance, I may have "cField1 = 'x'" and in another instance "cField2 = 'y' .AND. !empty(cField1)". Is this possible? I had attempted the following but it did not work: "create sql view test as select * from myTable where ?x"
>then before issuing the "use test" I assigned x="cField1 = 'x'". I would appreciate any suggestions.
The problem is with the statement. If you really, absolutely need the generality of a single parameterizedview containing the expression to evaluate for the where, rather than the argument, you'd have to code something like:
CREATE SQL VIEW Test AS SELECT * FROM MyTable WHERE EVAL(?x)
This is never optimizable.
If you're always going to test cFiedl1, the following would be infinitely better, and optimizable:
CREATE SQL VIEW Test AS SELECT * FROM MyTable WHERE cField1 = ?x
and now assign "X" to x before USE Test or requerying, eg:
x= "x"
USE Test
You could now have a second view to check some other condition...as needed.