Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What is the Best way?

Status
Not open for further replies.

geminihk

Programmer
Nov 11, 2002
21
0
0
HK
Hi,

I ve a table with the following structure:

Col1 Col2 Col3 Col4
AA 3000 BB 2000
BB 5000 AA 1000
CC 2000 BB 500
AA 1200 CC 300
BB 500 CC 100
AA 1000

I want to get a result as follows:

RC1 RC2
AA 6200
BB 8000
CC 2400

I used cursor still not getting the exact result & not know how to retun a this from the SP.

I would like to use SP to return the result set to he user.

Thanks.
 
Code:
select col1,sum(col2)
from 
(select col1,col2 from t
union all
select col3,col4 from t) dt
group by col1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top