Results 1 to 7 of 7

Thread: SQL

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Posts
    343

    Question

    I want to calculate the sum of "price" in a orders table into a variable....

    I tried this..

    sSql = "select sum(price) into intPrice from orders where client = 007"

    This does not work.

    Can anyone please help!!??

  2. #2
    Addicted Member Skeen's Avatar
    Join Date
    Jul 2000
    Location
    Abingdon, Oxon
    Posts
    138
    Hi

    I'm quite new to SQL and VB but could you try this:

    sSQL= "SELECT Sum(price) FROM Orders WHERE Client = '" & 007 & "' "

    Set rsSUM = ConnectionObject.Execute( sSQL )
    rsSUM.MoveFirst
    SumTotal =rsSUM( "price" )

    ssSQL= "INSERT INTO intPrice FieldName Values '" & SumTotal & "'
    Set rsInsert = ConnectionObject.Execute( ssSQL )


    Its probably bullshit, but I'm trying something similar at the moment and this seems like should work to me, No promisses though.

    In abit 'G'

    Skeen
    "It wasn't the booze that made me snooze, It was the Gin that did me in!"

  3. #3
    Lively Member
    Join Date
    Jun 2000
    Location
    A caravan park in the Midlands (UK)
    Posts
    101

    Lightbulb

    Are you wanting to contain this SQL all within the DB environment or are you asigning the result to a VB var?

    If the former then the following works for SQL Server...

    DECLARE @mySum as DECIMAL (12)

    SELECT @mySum =
    (SELECT sum(price) FROM orders WHERE blah = blah)

    Anakim

    It's a small world but I wouldn't like to paint it.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Posts
    343

    Unhappy

    Anakim,

    I want to assign the result to a VB variable!!

    I'm ripping my hair out on this side!!

  5. #5
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539

    this shold work

    Code:
    dim TotalPrice as Currency
    SQL ="SELECT SUM(price)as SumOfPrice FROM Orders WHERE client = 007"
    rs.open sql, db
    TotalPrice = rs!SumOfPrice
    that should work
    samething as yours, you were just missing "as"

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Posts
    343

    Talking

    Thanks kovan,

    This works 100%

  7. #7

Posting Permissions

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



Click Here to Expand Forum to Full Width