Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Sum the column values

Author  Topic 

vignesht50
Yak Posting Veteran

82 Posts

Posted - 2014-04-11 : 05:20:43
Hi,

I have this query where I do certain conversions and on top of this how can I sum the column values.

'$ '+ Replace(CONVERT(varchar,CAST(Total_Amount AS money),1) ,'.00','') as Total_Amount,
'$ '+ Replace(CONVERT(varchar,CAST(Monthly_Amount As money),1),'.00','') as Monthly_Amount,

Robowski
Posting Yak Master

101 Posts

Posted - 2014-04-11 : 07:52:32
USE tempdb;
GO

IF OBJECT_ID ('#TempTable', 'U') IS NOT NULL
DROP TABLE #TempTable;
GO

CREATE TABLE #TempTable (ColumnOne int not null, ColumnTwo int not null)

INSERT #TempTable
VALUES (2,2);
INSERT #TempTable
VALUES (2,2);
GO


;WITH CTE_Sum
AS
(
SELECT CAST(ColumnOne as MONEY) as TotalAmount ,
CAST(ColumnTwo as MONEY) as MonthlyAmount
FROM #TempTable
)

SELECT '$' + CAST(SUM(TotalAmount) as varchar) as TotalAmount ,
'$' + CAST(SUM(MonthlyAmount) as varchar) as MonthlyAmount
FROM CTE_Sum
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2014-04-11 : 08:05:29
This is the formation issue that should be done in a front end application unless you export the result to a text file

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -