Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

"combine" the results of a stored proc?

Posted on 2013-01-31
4
Medium Priority
?
158 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
[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
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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

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 the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

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