HAVING clause with Count(*)

Posts   
 
    
smurrell
User
Posts: 59
Joined: 22-Feb-2007
# Posted on: 17-Apr-2007 16:38:04   

Hello

How would I achieve the following command using a RelationPredicateBucket. I have a typedlist and I need to add the following clause to the typedlist.

Regards, Simon

HAVING 
        Count(*) =
        (
        SELECT
            Count(*)
        FROM
            tblDocumentGroupingDocumentType
        WHERE
            tblDocumentGroupingDocumentType.ifkDocumentGroupingID = @XYZ
        )
Aurelien avatar
Aurelien
Support Team
Posts: 162
Joined: 28-Jun-2006
# Posted on: 17-Apr-2007 16:57:55   

Hi,

You can see the Generated code - using GROUP BY and HAVING clauses section in the documentation.

smurrell
User
Posts: 59
Joined: 22-Feb-2007
# Posted on: 17-Apr-2007 17:12:34   

Aurelien wrote:

Hi,

You can see the Generated code - using GROUP BY and HAVING clauses section in the documentation.

I understand it, but how do I make a Count(*) = to a sub query.

DvK
User
Posts: 318
Joined: 22-Mar-2006
# Posted on: 17-Apr-2007 22:22:17   

Use a ScalarQueryExpression, see the documentation for more info -> Generated code - Field expressions and aggregates

smurrell
User
Posts: 59
Joined: 22-Feb-2007
# Posted on: 18-Apr-2007 07:32:14   

DvK wrote:

Use a ScalarQueryExpression, see the documentation for more info -> Generated code - Field expressions and aggregates

Hello Dvk

I got it right by fluke I think. I got it after chatting to the Aurelien. Here is the code which I have posted below for everyone else to know.

Regards, Simon


                    groupBy.HavingClause = new PredicateExpression();
                    groupBy.HavingClause.Add(new FieldCompareSetPredicate(
                        DocumentGroupingDocumentTypeFields.DocumentGroupingId.SetAggregateFunction(AggregateFunction.Count),
                        null,
                        DocumentGroupingDocumentTypeFields.DocumentGroupingId.SetAggregateFunction(AggregateFunction.Count),
                        null,
                        SetOperator.Equal,
                        (DocumentGroupingDocumentTypeFields.DocumentGroupingId == ID),
                        false));