Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL sum

Author  Topic 

syncode17
Starting Member

1 Post

Posted - 2010-03-25 : 19:11:51
Is there a way or code in SQL that i can add all repeating records in my database?
for example
SerialCode itemcode ItemName quantity
S001 A100 Pen 10
S002 A100 Pen 20
S003 A100 Pen 30

and i need the output of

itemcode itemname quantity
A100 Pen 30

(:>,<:)
syncode17

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-03-25 : 19:44:11
yes. it is SUM() with GROUP BY


select itemcode, itemname, sum(quantity)
from yourtable
group by itemcode, itemname



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-03-26 : 02:08:57
quote:
Originally posted by khtan

yes. it is SUM() with GROUP BY


select itemcode, itemname, sum(quantity)
from yourtable
group by SerialCode, itemcode, itemname



KH
[spoiler]Time is always against us[/spoiler]





As per the required output query should be like above see the red part in the query.

Vaibhav T
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-03-26 : 02:13:54
quote:
Originally posted by syncode17

Is there a way or code in SQL that i can add all repeating records in my database?
for example
SerialCode itemcode ItemName quantity
S001 A100 Pen 10
S002 A100 Pen 20
S003 A100 Pen 30

and i need the output of

itemcode itemname quantity
A100 Pen 30

(:>,<:)
syncode17



you wanted the record of A100 with the highest quantity ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-03-26 : 02:42:44
Yes Khtan this information is must
because from the post its not clear to which partition he is calling repeating records as per the sample data nothing is repeating even we remove the quantity.

Vaibhav T
Go to Top of Page
   

- Advertisement -