How to filtering using "LIKE" and several string

Posts   
 
    
JCroain
User
Posts: 10
Joined: 08-Dec-2006
# Posted on: 28-Feb-2007 10:34:03   

Hello all,

I work on SQL Server and use LLBL v2.0 adapter, .NET 2.0.50727.

I need to construct a sql statement like that to obtain invoices


AND ([T_FACTURES].[FAC_S_ID] LIKE '%/ AA'
OR [T_FACTURES].[FAC_S_ID] LIKE '%/ DA' 
OR [T_FACTURES].[FAC_S_ID] LIKE '%/ AV')

This is my code


foreach (DataRow dr in sousRequete.Rows)
            {
                param = "%/ " + dr.ItemArray[0];
                if (first)
                {
                    bucket.PredicateExpression.Add(TFacturesFields.FacSId % param);
                    first = false;
                }
                else
                {
                    bucket.PredicateExpression.AddWithOr(TFacturesFields.FacSId % param);
                }
            }

But the generated sql is


AND [T_FACTURES].[FAC_S_ID] LIKE '%/ AA'
OR [T_FACTURES].[FAC_S_ID] LIKE '%/ DA' 
OR [T_FACTURES].[FAC_S_ID] LIKE '%/ AV'

() missing in my sql statement and my result is not correct.confused

Could you help me simple_smile

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 28-Feb-2007 11:11:27   

Place all predicates which have to be placed inside () in a separate PredicateExpression object, and add THAT to the main predicate expression. So your predicates you add with OR should be in their own separate PredicateExpression, then you should add that one with AND to the main predicate expression.

Frans Bouma | Lead developer LLBLGen Pro
JCroain
User
Posts: 10
Joined: 08-Dec-2006
# Posted on: 28-Feb-2007 11:41:00   

Thanks for your response.

With this code, I obtain the correct result.


            IPredicateExpression predicat = new PredicateExpression();
            
            foreach (DataRow dr in sousRequete.Rows)
            {
                param = "%/ " + dr.ItemArray[0];
                if (first)
                {
                    predicat.Add(TFacturesFields.FacSId % param);
                    first = false;
                }
                else
                {
                    predicat.AddWithOr(TFacturesFields.FacSId % param);
                }
            }
            bucket.PredicateExpression.Add(predicat);