how to sum up a column value using the other column value

bajivali shaik

i have a stored procedure

ALTER  PROCEDURE [dbo].[PaymentServiceDetailBusinessUnit]
(
--@MRRId INT ,
@POId INT ,
@SDId INT 

)

AS
BEGIN

SELECT  BusinessUnit  , E1Description,Fund,SpendPriority,ServiceType,
 REUId , RCUId,  POId, PRR_Id, SUM (PaymentAmount) as TotalPaymentAmount
 FROM 
 (
SELECT  BU.BusinessUnit , BU.E1Description,BU.Fund,BU.SpendPriority,BU.ServiceType,
REU.Id AS REUId ,RCU.Id AS RCUId, PaymentAmount,PO.Id as POId, REU.PRR_Id
FROM [EBSTest].[dbo].[PaymentDetail] PD
     JOIN PurchaseOrder PO ON PO.Id = PD.PO_Id
     JOIN fBusinessUnit BU ON BU.id = PD.BU_Id
LEFT JOIN Reimbursement_EBSUtilization REU ON REU.Id = PD.REU_Id
LEFT JOIN Reimbursement_CDSUtilization RCU ON RCU.Id = PD.RCU_Id
LEFT JOIN ProviderReimbursementRequest PRR ON (PRR.Id = REU.PRR_Id  OR PRR.Id = RCU.PRR_Id)
LEFT JOIN CDSUtilization CDS ON CDS.Id = RCU.CDSU_Id


WHERE 
PO.Id = @POId  AND 
--PRR.MRR_Id = @MRRId AND 
(REU.SD_Id = @SDId OR CDS.ServiceDetail_Id  = @SDId)
) AS dt

GROUP BY 
BusinessUnit , E1Description,Fund,SpendPriority,ServiceType,REUId , RCUId, POId,PRR_Id



END 

the out put is

BusinessUnit    E1Description   Fund    SpendPriority   ServiceType REUId RCUId POId    PRR_Id  TotalPaymentAmount
10000002    MVBsd1hnhg  CF  Normal  SA  2331    NULL    12  934 100.00
10000002    MVBsd1hnhg  CF  Normal  SA  2346    NULL    12  935 60.00
10000002    MVBsd1hnhg  CF  Normal  SA  2361    NULL    12  937 40.00
10000002    MVBsd1hnhg  CF  Normal  SA  2389    NULL    12  941 40.00
10000002    MVBsd1hnhg  CF  Normal  SA  2406    NULL    12  943 40.00

but i want to show only one record with the total sum of total payment amount using the businessunit column -10000002 ie.

some thing like this

**10000002**    MVBsd1hnhg  CF  Normal  SA  2331    NULL    12  934 **280.00**

can any one help me on this?

Max Sorin

Remove REUId , RCUId, POId,PRR_Id from the Group By clause, as those appear to be causing the partitioning of the sum aggregation.

SELECT  BusinessUnit  , E1Description,Fund,SpendPriority,ServiceType,
 SUM (PaymentAmount) as TotalPaymentAmount
 FROM 
 (
SELECT  BU.BusinessUnit , BU.E1Description,BU.Fund,BU.SpendPriority,BU.ServiceType,
REU.Id AS REUId ,RCU.Id AS RCUId, PaymentAmount,PO.Id as POId, REU.PRR_Id
FROM [EBSTest].[dbo].[PaymentDetail] PD
     JOIN PurchaseOrder PO ON PO.Id = PD.PO_Id
     JOIN fBusinessUnit BU ON BU.id = PD.BU_Id
LEFT JOIN Reimbursement_EBSUtilization REU ON REU.Id = PD.REU_Id
LEFT JOIN Reimbursement_CDSUtilization RCU ON RCU.Id = PD.RCU_Id
LEFT JOIN ProviderReimbursementRequest PRR ON (PRR.Id = REU.PRR_Id  OR PRR.Id = RCU.PRR_Id)
LEFT JOIN CDSUtilization CDS ON CDS.Id = RCU.CDSU_Id


WHERE 
PO.Id = @POId  AND 
--PRR.MRR_Id = @MRRId AND 
(REU.SD_Id = @SDId OR CDS.ServiceDetail_Id  = @SDId)
) AS dt

GROUP BY 
BusinessUnit , E1Description,Fund,SpendPriority,ServiceType

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How to create a cumulative sum column in python if column value is greater than other value

From Java

Replace column value based on value in other column

From Dev

how to increment value of a column up to specific range for values in other column?

From Dev

update and using sum to calculate column value

From Dev

Using CASE to update column value depending on other column values

From Dev

calculate sum based on value of other row in another column

From Dev

Excel - CountIfs using column header and value from other column as criteria?

From Dev

How to decreasing value based on other column in SQL

From Dev

How to sum value at every step of CSV Column

From Dev

Sum up column by value and group in R

From Dev

SQL Server : How to sum respectively column value to next column

From Dev

How to Count/Sum a Column depending on a value of another Column

From Dev

SUM depending on column value

From Dev

update and using sum to calculate column value

From Dev

How to sum up to column specified in other cell in Drive Sreadsheet

From Dev

Oracle : SUM Column of only duplicates value of other column

From Dev

How to Get Max Value and Return Other Column

From Dev

excel vba : Sum up column value to last column

From Dev

How to Sum value according to other column value in cakephp

From Dev

How Can I sum up the column with decimal value in C# crystal report

From Dev

Using a Matrix to Populate Every Other Value in a Column

From Dev

How to sum a value of another column if column A = column B?

From Dev

How to explode by using a column value?

From Dev

How to count the sum of the value in 1 column and with the same value of another column?

From Dev

Is that possible? How to sum a number with database column value using only Query

From Dev

Use VBA to look up a value in a column, then sum up the value in the adjacent column

From Dev

How to update a column using another column value?

From Dev

PHP MySQL How to make mysql sum column if value of other column equals to apple

From Dev

How to sum a column with a foreign value selecting by id

Related Related

  1. 1

    How to create a cumulative sum column in python if column value is greater than other value

  2. 2

    Replace column value based on value in other column

  3. 3

    how to increment value of a column up to specific range for values in other column?

  4. 4

    update and using sum to calculate column value

  5. 5

    Using CASE to update column value depending on other column values

  6. 6

    calculate sum based on value of other row in another column

  7. 7

    Excel - CountIfs using column header and value from other column as criteria?

  8. 8

    How to decreasing value based on other column in SQL

  9. 9

    How to sum value at every step of CSV Column

  10. 10

    Sum up column by value and group in R

  11. 11

    SQL Server : How to sum respectively column value to next column

  12. 12

    How to Count/Sum a Column depending on a value of another Column

  13. 13

    SUM depending on column value

  14. 14

    update and using sum to calculate column value

  15. 15

    How to sum up to column specified in other cell in Drive Sreadsheet

  16. 16

    Oracle : SUM Column of only duplicates value of other column

  17. 17

    How to Get Max Value and Return Other Column

  18. 18

    excel vba : Sum up column value to last column

  19. 19

    How to Sum value according to other column value in cakephp

  20. 20

    How Can I sum up the column with decimal value in C# crystal report

  21. 21

    Using a Matrix to Populate Every Other Value in a Column

  22. 22

    How to sum a value of another column if column A = column B?

  23. 23

    How to explode by using a column value?

  24. 24

    How to count the sum of the value in 1 column and with the same value of another column?

  25. 25

    Is that possible? How to sum a number with database column value using only Query

  26. 26

    Use VBA to look up a value in a column, then sum up the value in the adjacent column

  27. 27

    How to update a column using another column value?

  28. 28

    PHP MySQL How to make mysql sum column if value of other column equals to apple

  29. 29

    How to sum a column with a foreign value selecting by id

HotTag

Archive