Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

"combine" the results of a stored proc?

Posted on 2013-01-31
4
Medium Priority
?
159 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:Tom Knowlton
  • 2
4 Comments
 
LVL 39

Assisted Solution

by:appari
appari earned 1000 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 1000 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:Tom 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:Tom Knowlton
ID: 39490681
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!

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

885 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