tags:

views:

530

answers:

1

Hi,

i need following SQL Expression for SubSonic I have to SUM 3 Columns and return the value in my result.

SubSonic.SqlQuery qs =new SubSonic.Select() .From(Table.ViewAllratingsGlo.Schema.TableName);

SubSonic.Aggregate ag = SubSonic.Aggregate.Sum(("Column1+Column2+Column3), "Score"); qs.Aggregates.Add(ag);

string SqlResult = qs.BuildSqlStatement();

In the Sql Statement i just see the Aggregate Query like Select SUM("Column1+Column2+Column3) As 'Score'

But i need the other fields from my table too.

Can anybody explain me how i can realize it

+1  A: 

In that kind of query, all the columns in your select statement need to be aggregate objects, just change the aggregate type to group by instead of sum.

SubSonic.SqlQuery qs = new Select(
    new SubSonic.Aggregate("column1+column2+column3", "Score", AggregateFunction.Sum), //the original
    new SubSonic.Aggregate(TableName.Column4, AggregateFunction.GroupBy), //another column
    new SubSonic.Aggregate(TableName.Column5, AggregateFunction.GroupBy) //another column
)
.From(Table.ViewAllratingsGlo.Schema.TableName);
ranomore