Solved

Adding Output from two SQL Scripts

Posted on 2011-02-15
3
260 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

688 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