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.
| 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.POSWHERE CLIENT_CODE = '993013002'SELECT SUM(MARKET_VALUE)'Mid Value'FROM dbo.POSWHERE CLIENT_CODE = '993007004'select SUM(MARKET_VALUE)'Grede'from dbo.POSWHERE CLIENT_CODE = '900091067'select SUM(MARKET_VALUE)'Sisters'from dbo.POSWHERE 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.POSwhere CLIENT_CODE IN ('993013002', '993007004', '900091067', '41L018011)group by CLIENT_CODE[/code] KH |
 |
|
|
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.5349999992900091067 7976614.3849999988993007004 601106955.32000005993013002 197607478.17724997to include a column that includes name, even though name isnt a field in the database, example:41L018011 4293391.5349999992 Test1900091067 7976614.3849999988 Test2993007004 601106955.32000005 Test3993013002 197607478.17724997 Test4So 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. |
 |
|
|
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' ... endfrom dbo.POSwhere CLIENT_CODE IN ('993013002', '993007004', '900091067', '41L018011)group by CLIENT_CODE KH |
 |
|
|
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' ... endfrom dbo.POSwhere CLIENT_CODE IN ('993013002', '993007004', '900091067', '41L018011)group by CLIENT_CODE KH
Most efficient way to get your desired result set |
 |
|
|
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. |
 |
|
|
humanpuck
Yak Posting Veteran
94 Posts |
Posted - 2006-07-20 : 09:10:52
|
He did all the work |
 |
|
|
|
|
|
|
|