Solved

loop through data suming up a field

Posted on 2014-04-15
2
172 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
2 Comments
 
LVL 11

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now