Solved

loop through data suming up a field

Posted on 2014-04-15
2
176 Views
Last Modified: 2014-04-15
DRUG_CODE      ChrgUnits        Pat_Num_CSN
3074              1                111111111
3074             -1                111111111
3000             -1                111111111
3000               1                111111111
3000              1                111111111

above data represents what I have, all stored as text. I'd like to loop through the data adding up the ChrgUnits based/grouped on the drug code and pat num csn and come up with this (in this example)

DRUG_CODE      ChrgUnits        Pat_Num_CSN
3074              0                111111111
3000              1                111111111
0
Comment
Question by:ghettocounselor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 12

Accepted Solution

by:
Missus Miss_Sellaneus earned 500 total points
ID: 40002491
Select DRUG_CODE, SUM(CAST(ChrgUnits AS int)) as Sum_ChrgUnits, Pat_Num_CSN from tablename GROUP BY DRUG_CODE, Pat_Num_CSN ORDER BY 1,3;
0
 

Author Closing Comment

by:ghettocounselor
ID: 40002538
appreciate the rapid response!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL query and VBA 5 55
SQL Query help 3 24
Return Rows as per Quantity of Columns Value In SQL 6 28
Please explain Equi-join 3 11
As they say in love and is true in SQL: you can sum some Data some of the time, but you can't always aggregate all Data all the time! Introduction: By the end of this Article it is my intention to bring the meaning and value of the above quote to…
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question