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
 Join Help

Author  Topic 

masond
Constraint Violating Yak Guru

447 Posts

Posted - 2013-09-20 : 03:22:56
Hey guys

Really quick one

Aim – Join the following two tables together by Fdmsaccountno and month_end_date

SELECT TOP 1000 [FDMSAccountNo]
,[Fee_Sequence_Number]
,[Month_end_date]
,[Retail_amount]
Into #42b
FROM [FDMS].[dbo].[Fact_Fee_History]
where Fee_Sequence_Number = '42b'


SELECT TOP 1000 [FDMSAccountNo]
,[Fee_Sequence_Number]
,[Month_end_date]
,[Retail_amount]
Into #42c
FROM [FDMS].[dbo].[Fact_Fee_History]
where Fee_Sequence_Number = '42c'

would appreciate any help available

bitsmed
Aged Yak Warrior

545 Posts

Posted - 2013-09-20 : 03:38:56
Mayby this:

select fdmsaccountno
,month_end_date
,sum(retail_amount_42b) as retail_amount_42b
,sum(retail_amount_42c) as retail_amount_42c
from (select fdmsaccountno
,month_end_date
,sum(retail_amount) as retail_amount_42b
,0 as retail_amount_42c
from #42b
group by fdmsaccountno
,month_end_date
select fdmsaccountno
,month_end_date
,0 as retail_amount_42b
,sum(retail_amount) as retail_amount_42c
from #42c
group by fdmsaccountno
,month_end_date
) as a
group by fdmsaccountno
,month_end_date
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-09-20 : 05:45:28
-- may be this is what you are looking for?
SELECT [FDMSAccountNo] ,[Month_end_date] ,SUM([Retail_amount]) [Retail_amount]
FROM [FDMS].[dbo].[Fact_Fee_History]
where Fee_Sequence_Number IN( '42b', '42c')
GROUP BY [FDMSAccountNo], [Month_end_date]



--
Chandu
Go to Top of Page

sigmas
Posting Yak Master

172 Posts

Posted - 2013-09-20 : 06:08:20
>>> Aim – Join the following two tables together by Fdmsaccountno and month_end_date

select *
from #42b a
join #42c b
on a.Fdmsaccountno =b.Fdmsaccountno
and a.month_end_date = b.month_end_date
Go to Top of Page
   

- Advertisement -