Results 1 to 3 of 3

Thread: [RESOLVED] ASP, ADO with SQL String Selection

  1. #1

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    150

    Resolved [RESOLVED] ASP, ADO with SQL String Selection

    Hi there,

    I'm struggling to select all "cOperationId" from the Table and get their combined sum by name and sum.

    I know how to query 1 by 1, but is there any solution to get all and list them?

    Code:
    Dim Sql, stDevId
    
    stDevId = "NPRCS-003"
    
    Sql = "SELECT COALESCE(SUM(cQuantity), 0) AS total FROM AppBlackBoxData WHERE cDeviceId='" & stDevId & "' AND cDate=CURDATE()"
    
    Set Rs = Db.Execute(Sql)
    
    Response.Write(Rs.Fields("total").Value)
    The database table looks like this:
    Name:  vb-sql-db-table.png
Views: 139
Size:  28.4 KB

    I would like to have output like this for example:
    Code:
    SW0001 = 1
    SW0002 = 2
    SW0003 = 3
    PK0004 = 7
    Any help would be appriciated,

    Kind regards,
    Viktor

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: ASP, ADO with SQL String Selection

    I'm not sure if I've interpreted your question properly, but I think this is what you are after:
    Code:
    SELECT cOperationId, SUM(cQuantity)
    FROM AppBlackBoxData 
    WHERE ...
    GROUP BY cOperationId

  3. #3

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    150

    Re: ASP, ADO with SQL String Selection

    Quote Originally Posted by si_the_geek View Post
    I'm not sure if I've interpreted your question properly, but I think this is what you are after:
    Code:
    SELECT cOperationId, SUM(cQuantity)
    FROM AppBlackBoxData 
    WHERE ...
    GROUP BY cOperationId
    That's it!!! +1

    Thank you sooo much!

Tags for this Thread

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