• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 263
  • Last Modified:

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

0
chokka
Asked:
chokka
  • 2
1 Solution
 
LowfatspreadCommented:
basically like this...

i cannot work out from your statement which select you wish modifying...
select Id,NDC,Qty +coalesce((select sum([dispensed qty]) from transactionreport as x where x.ndc=b.ndc),0) as qty
,CreatedDate from BalanceReport as b

Open in new window

0
 
chokkaAuthor Commented:
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

0
 
chokkaAuthor Commented:
Thank you
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now