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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Help With SUM Query

Author  Topic 

duhaas
Constraint Violating Yak Guru

310 Posts

Posted - 2006-07-19 : 22:13:46
I run the following:
SELECT SUM(MARKET_VALUE)'Small Growth'
FROM dbo.POS
WHERE CLIENT_CODE = '993013002'

SELECT SUM(MARKET_VALUE)'Mid Value'
FROM dbo.POS
WHERE CLIENT_CODE = '993007004'

select SUM(MARKET_VALUE)'Grede'
from dbo.POS
WHERE CLIENT_CODE = '900091067'

select SUM(MARKET_VALUE)'Sisters'
from dbo.POS
WHERE CLIENT_CODE = '41L018011'

and get 4 different result sets, I want to return one result set, with each column reads Sister and than the sum, Grede and than the sum, how can i join them together? I can with union, but the results all display in one colum, and get the first statements name.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-07-19 : 22:21:13
[code]select CLIENT_CODE, SUM(MARKET_VALUE)
from dbo.POS
where CLIENT_CODE IN ('993013002', '993007004', '900091067', '41L018011)
group by CLIENT_CODE[/code]


KH

Go to Top of Page

duhaas
Constraint Violating Yak Guru

310 Posts

Posted - 2006-07-20 : 08:10:42
Appreciate the quick response, maybe I didnt ask the question correctly, I want the results that I get:

41L018011 4293391.5349999992
900091067 7976614.3849999988
993007004 601106955.32000005
993013002 197607478.17724997

to include a column that includes name, even though name isnt a field in the database, example:

41L018011 4293391.5349999992 Test1
900091067 7976614.3849999988 Test2
993007004 601106955.32000005 Test3
993013002 197607478.17724997 Test4

So in this case, I was thinking I could somehow assign a name to the output even though its not grabbing the name for any defined field.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-07-20 : 08:25:06
is it something like this ?
select CLIENT_CODE, SUM(MARKET_VALUE),
case when CLIENT_CODE = '41L018011' then 'Test1'
when CLIENT_CODE = '900091067' then 'Test2'
...
end
from dbo.POS
where CLIENT_CODE IN ('993013002', '993007004', '900091067', '41L018011)
group by CLIENT_CODE



KH

Go to Top of Page

humanpuck
Yak Posting Veteran

94 Posts

Posted - 2006-07-20 : 08:52:50
quote:
Originally posted by khtan

is it something like this ?
select CLIENT_CODE, SUM(MARKET_VALUE),
case when CLIENT_CODE = '41L018011' then 'Test1'
when CLIENT_CODE = '900091067' then 'Test2'
...
end
from dbo.POS
where CLIENT_CODE IN ('993013002', '993007004', '900091067', '41L018011)
group by CLIENT_CODE



KH





Most efficient way to get your desired result set
Go to Top of Page

duhaas
Constraint Violating Yak Guru

310 Posts

Posted - 2006-07-20 : 09:09:18
You guys ROCK, I appreciate your help, being new to SQL its great to have people like you guys that are willing to help.
Go to Top of Page

humanpuck
Yak Posting Veteran

94 Posts

Posted - 2006-07-20 : 09:10:52
He did all the work
Go to Top of Page
   

- Advertisement -