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
 Adding a table with the same id#

Author  Topic 

marino3d
Starting Member

18 Posts

Posted - 2011-02-22 : 12:42:53

a

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2011-02-22 : 12:48:28
Select NameID,Sum(TransactAmount) TransactTotal
From TableName
Where TransactType in ('C','D')
Group by NameID

Cheers
MIK
Go to Top of Page

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2011-02-22 : 15:18:04

execute the below ..


Declare @tab table (a int, b varchar(10), c Numeric (4,2))
insert into @tab values (007,'C',15.00),(123,'D',10.00),(007,'D',5.00),(555,'D',10.00),(123,'D',5.00),(007,'D',10.00),(555,'F',15.00),(555,'C',5.00)

select x.a,SUM(x.c)
from @tab x
where exists (select a from @tab where a=x.a group by a having COUNT(distinct b)>1)
and b in ('c','d')
group by x.a

Union all

Select A, sUM(0.00)
from @tab where a not in (
select x.a
from @tab x
where exists (select a from @tab where a=x.a group by a having COUNT(distinct b)>1) and b in ('c','d')
) AND b in ('c','d')
Group by a

just to give you an idea
Go to Top of Page
   

- Advertisement -