| Author |
Topic |
|
krishna_yess
Yak Posting Veteran
81 Posts |
Posted - 2008-09-18 : 08:51:50
|
Hi, i have this table------ -----Cat Value------ ------A_4D 100A_E44 100A_3DF 200A_RT 300B_RY75 120B_RR 129B_ERT 123C_DGTY 134C_F 234C_F 444D_FGDS 23D_F 3444D_DFG 435D_S 345D_SDF 345D_G 345D_DFG 3344-------------- i need to generate a summary of values group by first letter in the first colum(i.e. group by A,B,C AND D)Finally it should look like this---------- -----Cat Value---------- -----A_ Total 700B_ Total 372C_ Total 812D_ Total 8281Grand Total 10165--------------------- please help |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-09-18 : 08:59:46
|
| select left(cat,charindex('_',cat)-1) as cat, sum(value) as value from tablegroup by left(cat,charindex('_',cat)-1) MadhivananFailing to plan is Planning to fail |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2008-09-18 : 09:02:26
|
| SELECT LEFT(t.Cat,1)+'_ Total' as CAT ,SUM(t.Value) as [Value]FROM YourTable tGROUP BY LEFT(t.Cat,1) |
 |
|
|
krishna_yess
Yak Posting Veteran
81 Posts |
Posted - 2008-09-18 : 09:16:35
|
Great, Thanks a lot Madhivanan.But i am not able to get other columns(other than cat). actually i have 3 columns like------ ----- ----- -----Cat Value 1 Value 2 Value 3------ ------ ------ ------A_4D 100 44 3A_E44 100 56 56A_3DF 200 6 6A_RT 300 6 345B_RY75 120 5 6B_RR 129 6 345B_ERT 123 6 456C_DGTY 134 4 56C_F 234 5 5C_F 444 4 56D_FGDS 23 6 6D_F 3444 5 5D_DFG 435 5 6D_S 345 5 5D_SDF 345 5 6D_G 345 5 5D_DFG 3344 5 5------ ------ ------ ------ |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-09-18 : 09:33:19
|
quote: Originally posted by krishna_yess Great, Thanks a lot Madhivanan.But i am not able to get other columns(other than cat). actually i have 3 columns like------ ----- ----- -----Cat Value 1 Value 2 Value 3------ ------ ------ ------A_4D 100 44 3A_E44 100 56 56A_3DF 200 6 6A_RT 300 6 345B_RY75 120 5 6B_RR 129 6 345B_ERT 123 6 456C_DGTY 134 4 56C_F 234 5 5C_F 444 4 56D_FGDS 23 6 6D_F 3444 5 5D_DFG 435 5 6D_S 345 5 5D_SDF 345 5 6D_G 345 5 5D_DFG 3344 5 5------ ------ ------ ------
So, what is your expected result?MadhivananFailing to plan is Planning to fail |
 |
|
|
krishna_yess
Yak Posting Veteran
81 Posts |
Posted - 2008-09-18 : 10:48:20
|
i need result like thisCat Value1 Value2 Value3A Total 700 112 410B Total 372 17 807C Total 812 13 117D Total 8281 36 38"Grand Total" 10165 178 1372 |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-09-18 : 11:41:04
|
quote: Originally posted by krishna_yess i need result like thisCat Value1 Value2 Value3A Total 700 112 410B Total 372 17 807C Total 812 13 117D Total 8281 36 38"Grand Total" 10165 178 1372
You can easily modify the query Try it MadhivananFailing to plan is Planning to fail |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-18 : 11:41:13
|
| [code]SELECT COALESCE(PARSENAME(REPLACE(Cat,'_','.'),2),PARSENAME(REPLACE(Cat,'_','.'),1)),SUM(Value1) AS Value1,SUm(Value2) AS Value2,SUM(Value3) AS Value3FROMGROUP BY COALESCE(PARSENAME(REPLACE(Cat,'_','.'),2),PARSENAME(REPLACE(Cat,'_','.'),1))[/code] |
 |
|
|
krishna_yess
Yak Posting Veteran
81 Posts |
Posted - 2008-09-18 : 11:54:20
|
| i got it thanks a lot |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-18 : 12:39:52
|
quote: Originally posted by krishna_yess i got it thanks a lot
welcome |
 |
|
|
|