Solved

loop through data suming up a field

Posted on 2014-04-15
2
177 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

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

707 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