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
 How to change group by result. please...

Author  Topic 

dhani
Posting Yak Master

132 Posts

Posted - 2009-02-12 : 19:56:15
Hello All,

please help me masters....

seems to be big question, but actually it is not, i elaborated clearely

in my Accounts_Info table, it has the below fields(AcctId is primary key) & data

AcctID,DIVID,Name
--------- -------- -------
PB123, AAA, ABC Corp
PB250,AAA, G&Man
VR320,BBB, Siebel Soft
PB321,CCC ,Menta Par
VR322,CCC,Kentichy
PB267,BBB,Komma Kocha
VR123,DDD,Global Vie
PB345,DDD, GSD&K
VR560,AAA, integer
.....
.....
VR870,AAA, Corptel


DailyTrans table has below fields

Trans#,AcctID,TransDate,Amount
1,PB123,2008-11-04,-10
2,PB123,2008-11-05 ,20
3,VR320,2008-11-05,25
4,PB123,2008-11-05,15
5,VR320,2008-11-06,-20
6,PB267,2008-11-07,15
7,VR870,2008-11-07,25
8,PB267,2008-11-08,30
9,VR560,2008-11-09,35
10,VR560,2008-11-09,35
.......

SELECT a.acctID,b.divid, b.name,sum(a.Amount)
FROM DailyTrans a,accounts_Info b
WHERE a.acctID=b.acctID
and (b.DivCode = 'AAA') AND (a.DataDate between '11/1/2008' and '11/30/2008')
group by a.acctID,b.divID,b.name
order by b.name

when i run the above sql query it results as below
acctID,divid,name,sum(amount)
-------- ------ ------ ----------------
PB123,AAA,ABC Corp,25
VR870,AAA,Corptel,25
VR560,AAA,integer,70

if i issue this command

SELECT b.divid,sum(a.Amount)
FROM DailyTrans a,accounts_Info b
WHERE a.acctID=b.acctID
and (b.DivCode = 'AAA') AND (a.DataDate between '11/1/2008' and '11/30/2008')
group by b.divID
acctID,divid,name,sum(amount)
-------- ------ ------ ----------------
AAA,120


upto here everything goes fine

now the question is, when i use second query i want it be if name='integer' then it appears as a separate group

such as below

acctID,divid,name,sum(amount)
-------- ------ ------ ----------------
AAA,50
integer,70

actually integer is a account name but it needs to be separate group please....

Could any one please help me

Please Masters

Thanks in advance
dhani

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-02-12 : 20:19:07
Can you post clearly you expected output?Also what about other name?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-12 : 20:38:53
[code]
SELECT DIVID,SUM(Amount) AS Total
FROM Account_Info ai
INNER JOIN DailyTrans dt
ON dt.AcctID=ai.AcctID
WHERE (b.DivCode = 'AAA') AND (a.DataDate between '11/1/2008' and '11/30/2008')
AND Name<>'integer'
GROUP BY DIVID

UNION ALL

SELECT Name,SUM(Amount)
FROM Account_Info ai
INNER JOIN DailyTrans dt
ON dt.AcctID=ai.AcctID
WHERE (b.DivCode = 'AAA') AND (a.DataDate between '11/1/2008' and '11/30/2008')
AND Name='integer'
GROUP BY Name
[/code]
Go to Top of Page

dhani
Posting Yak Master

132 Posts

Posted - 2009-02-13 : 14:32:30
Thank you very much Visakh

its really worked well as i need
thank you very much

also sodeep thanks for your intention to solve my problem

really apreciate all

Regards
Dhani
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-14 : 00:47:16
welcome
Go to Top of Page
   

- Advertisement -