Link to home
Start Free TrialLog in
Avatar of chokka
chokkaFlag for United States of America

asked on

Adding Output from two SQL Scripts

SQL 2008

I have two Tables :-

BalanceReport
TransactionReport

I need to Add BalanceReport.Qty to TransactionReport.Qty for its Corresponding NDC Column

Incase if NDC is not matching, then i need to just include the BalanceReport - NDC:Qty to Transaction Report.

I really need experts help to resolve this issue





select Id,NDC,Qty,CreatedDate from BalanceReport



select		GenericCode,  
			NDC,   
			Sum([Dispensed Qty]) as TotalDispensed
from		TransactionReport    
Group By  GenericCode,NDC

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Lowfatspread
Lowfatspread
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chokka

ASKER

I did it in this way.

Anyways thank you for your help
Create Proc usp_TotalTransaction
As
Begin

declare @TempTable table
( 
	NDC nvarchar(1000), 
	Qty nvarchar(1000) 
)

Insert Into @TempTable (NDC,Qty)
select		
			
			TR.NDC,   
			Sum(TR.[Dispensed Qty]) as Qty
from		TransactionReport TR    
Group By    TR.NDC

Insert Into @TempTable (NDC,Qty)
select BR.NDC,BR.Qty  from BalanceReport BR


select NDC,Sum(CONVERT(INT, Qty)) as Qty from  @TempTable
Group By NDC

End

Open in new window

Avatar of chokka

ASKER

Thank you