Solved

Adding Output from two SQL Scripts

Posted on 2011-02-15
3
255 Views
Last Modified: 2012-06-21
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
Comment
Question by:chokka
  • 2
3 Comments
 
LVL 50

Accepted Solution

by:
Lowfatspread earned 500 total points
ID: 34901304
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
 

Author Comment

by:chokka
ID: 34901355
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
 

Author Closing Comment

by:chokka
ID: 34901358
Thank you
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This video discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now