× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



On 1/7/11 2:08 PM, Bryce Martin wrote:
I might be trying to be too fancy here, but I thought that maybe
this would work.

I have an array of values (words) that I need to search a particular
field for in a file.... So I thought that this might work...

Exec SQL
Declare NameSet Cursor For
Select Cast(rncust As Numeric(6,0)),
Cast(rnseq As Numeric(4,0)),
Cast(rntype As Numeric(2,0)),
rnword1, rnword2, rnword3, rnword4, rnword5
From rcm002pf
Where rnword1 in(:NameString)
and rntype = (case when :type<>''
then :NumType else rntype
End)
Order by rncust, rnseq;

I build NameString from the array values. Its a character string.
Its value is like... 'word1','word2','word3'

My thinking is that NameString would just plop right inside the IN()
clause and act as the list to check. But I keep getting and sql 100
error (no results). If I put this into my favorite sql tool it works
fine. So I know that its something to do with the SQL. I thought this
would be cleaner than doing a Prepare, but maybe I'll have to do it
anyway.

Addendum from another post:
I actually have 5 different columns I need to do this with so I
was trying to be a bit more succinct and use just 1 host variable
5 times instead of 5 host variables 5 times. Plus, I only want to
include the host variable if it isn't equal to *blanks, so I guess
I'm just going to have to build and prepare the statement.

Any thoughts????


A CASE statement can be used for the values of the IN, just as the CASE is used on the right side of the equal sign. Making each token\word as its own variable, given that the database NULL value is not valid for equivalence [neither equal nor IN predicate], plus that the null\empty string is not valid for search according to the addendum, consider the following modification to allow the static SQL:

WHERE rnword1 IN ( NullIf(:NameVal1, '')
, NullIf(:NameVal2, '')
, NullIf(:NameVal3, '')
, NullIf(:NameVal4, '')
, NullIf(:NameVal5, '') )
and rntype = (case when :type<>''
then :NumType else rntype
End)

Note: NULLIF scalar is just a "special case" of the CASE

Regards, Chuck

As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.