Problem in MAX Function

Posts   
 
    
Posts: 97
Joined: 29-Apr-2009
# Posted on: 07-May-2009 13:41:27   

Hello,

I have following Table :CMS_ContentDetails

i have following fields

intContentDetailId -> int intNodeID -> int intNodeParentID -> int intNodeOrder -> int

i want to find following query :

SELECT @intNodeOrder= ISNULL(MAX(intNodeOrder),0)+1 FROM CMS_ContentDetails WHERE intNodeParentID = @intNodeParentID AND flgDeleted = 0

how can i achieve result without using store procedure. i am using self servicing.

above query will give you max intNodeOrder from CMS_ContentDetails.

problem is that i dont want to use store procedure. so how can i achieve this ???

i have refer the followinf link but cant understand how to implement

http://www.llblgen.com/documentation/2.6/Using%20the%20generated%20code/gencode_expressionsaggregates.htm

Thanks.

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 07-May-2009 18:09:35   

What have you tried so far....?

Matt

Posts: 97
Joined: 29-Apr-2009
# Posted on: 08-May-2009 05:21:05   

MTrinder wrote:

What have you tried so far....?

Matt

Hi Matt,

Thanks for reply.

well i want to find max number of IntNodeorder Filed. so i am trying by following

IPredicateExpression filter = new PredicateExpression(); filter.Add(CmsContentDetailsFields.InNodeParentId == Convert.ToInt32(drpCategory.SelectedValue));

            ResultsetFields fields = new ResultsetFields(1);
            fields.DefineField(CmsContentDetailsFields.IntNodeOrder, 0);
            PredicateExpression OrderFilter = new PredicateExpression();
            OrderFilter.Add(CmsContentDetailsFields.InNodeParentId == Convert.ToInt32(drpCategory.SelectedValue));
            OrderFilter.Add(CmsContentDetailsFields.FlgDeleted == false);
            TypedListDAO dao = new TypedListDAO();
            IDataReader reader = dao.GetAsDataReader(null, fields, OrderFilter, null, CommandBehavior.CloseConnection, 0, true);
            int i = 0;
            while (reader.Read())
            {
                i++;
            }

now "i" will give the max value.

but i think this is too long.

is there any other option so i can get max number of IntNodeOrder?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 08-May-2009 07:03:13   

Hi Sitapara, I would do that this way:

IPredicateExpression filter = new PredicateExpression(
        CmsContentDetailsFields.InNodeParentId == Convert.ToInt32(drpCategory.SelectedValue) 
        & CmsContentDetailsFields.FlgDeleted == false);

object res = new CmsContentDetailsCollection().GetScalar(CmsContentDetailsFieldIndex.IntNodeOrder, 
        null, AggregateFunction.Max, filter);

int maxIntNodeOrder = (res == null) ? 0 : (int)res;
David Elizondo | LLBLGen Support Team
Posts: 97
Joined: 29-Apr-2009
# Posted on: 08-May-2009 07:31:19   

daelmo wrote:

Hi Sitapara, I would do that this way:

IPredicateExpression filter = new PredicateExpression(
        CmsContentDetailsFields.InNodeParentId == Convert.ToInt32(drpCategory.SelectedValue) 
        & CmsContentDetailsFields.FlgDeleted == false);

object res = new CmsContentDetailsCollection().GetScalar(CmsContentDetailsFieldIndex.IntNodeOrder, 
        null, AggregateFunction.Max, filter);

int maxIntNodeOrder = (res == null) ? 0 : (int)res;

hi daelmo,

thanks for reply

it gives error like this :

The name 'CmsContentDetailsFieldIndex' does not exist in the current context

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 08-May-2009 07:39:02   

Make sure you include this using statement (where the FieldIndex enums) resides:

using <YourRootNamespace>.HelperClasses;
David Elizondo | LLBLGen Support Team
Posts: 97
Joined: 29-Apr-2009
# Posted on: 08-May-2009 07:59:51   

daelmo wrote:

Make sure you include this using statement (where the FieldIndex enums) resides:

using <YourRootNamespace>.HelperClasses;

hi daelmo,

i have added following namespace

using Rigelnetworks.CollectionClasses; using Rigelnetworks.DaoClasses; using Rigelnetworks.EntityClasses; using Rigelnetworks.FactoryClasses; using Rigelnetworks.HelperClasses; using Rigelnetworks.Linq; using Rigelnetworks.RelationClasses; using Rigelnetworks.StoredProcedureCallerClasses; using System.IO; using SD.LLBLGen.Pro.ORMSupportClasses; using SD.LLBLGen.Pro.DQE.SqlServer;

but still it gives error

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 08-May-2009 10:35:11   

Try this:

using Rigelnetworks;
Posts: 97
Joined: 29-Apr-2009
# Posted on: 08-May-2009 10:59:27   

Walaa wrote:

Try this:

using Rigelnetworks;

Hey walaa,

thanks it is working.

you the best.smile

Posts: 97
Joined: 29-Apr-2009
# Posted on: 08-May-2009 11:07:32   

manoj.sitapara wrote:

daelmo wrote:

Hi Sitapara, I would do that this way:

IPredicateExpression filter = new PredicateExpression(
        CmsContentDetailsFields.InNodeParentId == Convert.ToInt32(drpCategory.SelectedValue) 
        & CmsContentDetailsFields.FlgDeleted == false);

object res = new CmsContentDetailsCollection().GetScalar(CmsContentDetailsFieldIndex.IntNodeOrder, 
        null, AggregateFunction.Max, filter);

int maxIntNodeOrder = (res == null) ? 0 : (int)res;

hi daelmo,

thanks for reply

it gives error like this :

The name 'CmsContentDetailsFieldIndex' does not exist in the current context

Hi daelmo

Thanks for solution, it helps me