Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

loop through data suming up a field

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

650 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