Link to home
Start Free TrialLog in
Avatar of Tom Knowlton
Tom KnowltonFlag for United States of America

asked on

"combine" the results of a stored proc?

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.

User generated image
SOLUTION
Avatar of appari
appari
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of ValentinoV
ValentinoV
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tom Knowlton

ASKER

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

Thank you.