Solved

Adding Output from two SQL Scripts

Posted on 2011-02-15
3
257 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

803 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