adding values to multiple columns

  • I would like to create a field/expression that would calculate the sum of a couple other fields? Is that possible or is that best left for VB code?

    here is my sql statement right now:

    SELECT drivernum,Sum(fuelchrg),Sum(tractorcost),Sum(CashAdvAmt),Sum(cashadvchrg),Sum(totamtdue),Sum(oilcost) from fuelinvoice group by drivernum

    So I want to add the sums of all those fields for my gtotal field.

    Matt

  • SELECT drivernum,Sum(fuelchrg),Sum(tractorcost),Sum(CashAdvAmt),Sum(cashadvchrg),Sum(totamtdue),Sum(oilcost) ,

    Sum(fuelchrg)+Sum(tractorcost)+Sum(CashAdvAmt)+Sum(cashadvchrg)+Sum(totamtdue)+Sum(oilcost) as gTotal

    from fuelinvoice group by drivernum

    with rollup

    ROLLUP generates a result set showing aggregates for a hierarchy of values in the selected columns. VAlue of drivernum will be null

    I hope this answers your question.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply