?
Solved

loop through data suming up a field

Posted on 2014-04-15
2
Medium Priority
?
178 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 2000 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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
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 …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month9 days, 13 hours left to enroll

762 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