Solved

"combine" the results of a stored proc?

Posted on 2013-01-31
4
146 Views
Last Modified: 2013-09-13
Is it possible to take the results of a stored proc and then SUM one of the columns, leaving all the other columns as they are?

The two rows returned are identical except for the amount.

sumexecsp
0
Comment
Question by:knowlton
  • 2
4 Comments
 
LVL 39

Assisted Solution

by:appari
appari earned 250 total points
ID: 38842049
if possible change it in the stored procedure itself, by using grouping. post your existing procedure script here.
0
 
LVL 37

Accepted Solution

by:
ValentinoV earned 250 total points
ID: 38842736
You can put the results of the SP into a temporary table or table variable through the following syntax:

INSERT INTO #YourTempTable
EXEC ...

This assumes that #YourTempTable already exists.  Once the data is in the temp table, you can use a regular SELECT statement to manipulate it any way you'd like.
0
 
LVL 5

Author Comment

by:knowlton
ID: 38844024
Here is the current T-SQL:

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[Marketing_Plan_RepairBidDetail_Get]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)

DROP PROCEDURE [dbo].[Marketing_Plan_RepairBidDetail_Get]

GO

CREATE PROCEDURE [dbo].[Marketing_Plan_RepairBidDetail_Get]

@RepairBidID	int,
@RepairBidSID	int

AS


select 
rb.BidCompany
,rih.RprEstCompletionDays
,subselRU.sumofamt
,rb.BidDocID 
,rb.BidDocSID
,rb.AssetTaskID
,rb.AssetTaskSID
,rb.RepairBidID
,rb.RepairBidSID
,rb.StatusID
From RepairBidForm rbf
join RepairBid rb on rb.RepairBidFormID = rbf.RepairBidFormID 
and rb.RepairBidFormSID = rbf.RepairBidFormSID
join RprInspHeader rih on rb.RepairBidID = rih.RepairBidID
join (select ru2.RepairBidID, ru2.RepairBidSID, sum(Amt) as sumofamt
from RepairUnit ru2
group by 
ru2.RepairBidID, 
ru2.RepairBidSID, 
(Amt)) subselRU on rb.RepairBidID = subselRU.RepairBidID
join RepairItem ri on rbf.RepairBidFormID = ri.RepairBidFormID
where 
subselRU.RepairBidID = @RepairBidID and subselRU.RepairBidSID = @RepairBidSID
group by
rb.BidCompany
,rih.RprEstCompletionDays
,subselRU.sumofamt
,rb.BidDocID
,rb.BidDocSID
,rb.AssetTaskID
,rb.AssetTaskSID
,rb.RepairBidID
,rb.RepairBidSID
,rb.StatusID
GO




 

Open in new window

0
 
LVL 5

Author Closing Comment

by:knowlton
ID: 39490681
Thank you.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
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.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

744 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

10 Experts available now in Live!

Get 1:1 Help Now