A Predicate that uses a Subquery

Posts   
 
    
Markiemac
User
Posts: 132
Joined: 25-Apr-2006
# Posted on: 22-Oct-2007 12:02:39   

Hi, (Using Ver 2.00/VB/Adapter/SQL Server 2K)

I'm trying to define LLBL code that returns a collection of DivCode & DivName fields from table tblDiv, that excludes DivCode entities present in another table. The SQL below shows what I'd like to do:

SELECT DivCode, DivName FROM tblDiv WHERE DivCode Not In (SELECT DivCode FROM DivProg WHERE ProgCode = 'XXX')

As I'm not familiar with using a subquery as a predicate, how would I do this?

Thanks

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 22-Oct-2007 12:15:28   

Please check the FieldCompareSetPredicate in the LLBLGen Pro docs and LLBLGen Pro reference manual. The filter should look like the following:

predicateExpression.Add(new FieldCompareSetPredicate(
    DivFields.DivCode, DivProg.DivCode,
    SetOperator.In, (DivProg.ProgCode == "XXX"), true));

The last true parameter os for negating the IN clause -> producing a NOT IN.

Markiemac
User
Posts: 132
Joined: 25-Apr-2006
# Posted on: 22-Oct-2007 18:16:06   

Walaa,

Great stuff!! Thankssimple_smile