Solved

How to sum the quantity or price on SQL Table SUM ()

Posted on 2013-01-16
2
611 Views
Last Modified: 2013-01-16
Our Drug Table has only 3 columns like GenericCode, DrugName, Qty.

SUM(QTY) is the Column which i expect to be along with my Select Query


GenericCode       DrugName         Qty           SUM(Qty)
102010                 ABC                  10                   40
102010                 ABC                  20                    40
102010                 ABC                  10                    40

102111                 EFG                  10                     20
102111                 EFG                  10                     20
0
Comment
Question by:chokka
2 Comments
 
LVL 41

Accepted Solution

by:
ralmada earned 500 total points
ID: 38783895
use this

select *, sum(qty) over (partition by GenericCode) from yourtable

More details:

http://msdn.microsoft.com/en-us/library/ms189461(v=sql.100).aspx
0
 
LVL 42

Expert Comment

by:zephyr_hex
ID: 38783909
select DrugName,sum(Qty) from DrugTable group by DrugName

i'm not clear from your data set whether you also want to group by GenericCode.  if that's the case, then
select GenericCode,DrugName,sum(Qty) from DrugTable group by GenericCode,DrugName
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

705 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

21 Experts available now in Live!

Get 1:1 Help Now