Results 1 to 8 of 8
  1. #1
    Join Date
    Dec 2002
    Posts
    3

    Question Unanswered: Update and sum colums

    Hello,

    I would like to to update table A and then the next record would
    show the sum of Column A and Column B.

    Example:

    select *
    from table A

    select sum (column A) as Total_1,sum(column b) as Total_2

    How can I write one view to handle both ??

    Thanks For Your Help
    Sam

  2. #2
    Join Date
    Feb 2002
    Posts
    2,232
    A view stores a select statement - I think you are referring to a stored procedure to handle an update and select as 1 object. Can you be more specific in your example (including sample data and specific sql statements - the update and select ) ?

  3. #3
    Join Date
    Dec 2002
    Posts
    3

    Question

    Example:

    select *
    from table A

    select sum (column A) as Amount,sum(column b) as Cost
    from table A



    Invoice# Amount Cost

    123 $4.67 $1.23
    342 $2.33 $0.75
    526 $17.60 $10.60
    $24.60 $12.58

    How can I write a query to updated Table A and then sum the Amount and Cost column?

    Thanks For Your Help
    Sam

  4. #4
    Join Date
    Feb 2002
    Posts
    2,232
    What is the update statement ? Also, what will receive the values returned from the 'select sum ...' - what will use these values ?

  5. #5
    Join Date
    Dec 2002
    Posts
    3
    How can I put these Two Select statements into one?

    select *
    from table A

    select sum (column A) as Amount,sum(column b) as Cost
    from table A

    Example:

    select * and sum (column A) as Amount,sum(column b) as Cost
    from table A


    Thanks For Your Help
    Sam

  6. #6
    Join Date
    Feb 2002
    Posts
    2,232
    select *, sum (column A) as Amount, sum(column b) as Cost
    from table A group by ...

    This is only useful if you have repeating invoice numbers - if there are no repeating invoice numbers then this is the same as select * from tableA

  7. #7
    Join Date
    Feb 2002
    Posts
    2,232
    Just to confirm - what are the records in the table - then what output do you want (use actual data for both in the table and the output desired) ?

  8. #8
    Join Date
    Dec 2002
    Location
    Czech Republic
    Posts
    249

    Re: Update and sum colums

    Originally posted by gurusam
    Hello,

    I would like to to update table A and then the next record would
    show the sum of Column A and Column B.
    Sam
    Do you want something like this:

    select InvoiceNum,Amount=sum(Amount),Cost=sum(Cost)
    from tableA
    group by InvoiceNum
    with rollup

    /*
    CREATE TABLE dbo.tableA
    (
    InvoiceNum int NOT NULL PRIMARY KEY,
    Amount money NOT NULL,
    Cost money NOT NULL
    )
    */

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •