September 23, 2021 at 3:24 pm
I'm needing to convert some varchar figures to decimal for sums, but can't quite find an example that works... the second block of code just returns the list of data without cast or sum:
SELECT
SUM(CAST([Convo] AS DECIMAL(10,2)))
,SUM(CAST([F9D2]) AS DECIMAL(10,2)))
,SUM(CAST([F9D5]) AS DECIMAL(10,2)))
,SUM(CAST([F9DMTM]) AS DECIMAL(10,2)))
,SUM(CAST([Exception]) AS DECIMAL(10,2)))
,SUM(CAST([Training]) AS DECIMAL(10,2)))
,SUM(CAST([TOTAL Time]) AS DECIMAL(10,2)))
FROM [a2hr].[dbo].[FinalPayroll] where period = 18
SELECT
[Convo]
,[F9D2]
,[F9D5]
,[F9DMTM]
,[Exception]
,[Training]
,[TOTAL Time]
FROM [a2hr].[dbo].[FinalPayroll] where period = 18
September 23, 2021 at 3:45 pm
What is the exact problem?
September 23, 2021 at 3:48 pm
Errors of 'Invalid Column Name': SUM(CAST([Convo] AS DECIMAL(10,2)))
Errors of 'Invalid Column Name': SUM(CAST([F902] AS DECIMAL(10,2))) SUM is not recognized as a valid function
etc.
September 23, 2021 at 4:22 pm
Does just this work?
SELECT
SUM(CAST([Convo] AS DECIMAL(10,2)))
FROM [a2hr].[dbo].[FinalPayroll] where period = 18
September 23, 2021 at 4:54 pm
I'm needing to convert some varchar figures to decimal for sums, but can't quite find an example that works... the second block of code just returns the list of data without cast or sum:
Heh... lordy. At least do a desk check of your code. What is with all the extra parentheses right after the column names?
--Jeff Moden
Change is inevitable... Change for the better is not.
September 23, 2021 at 5:11 pm
Yes this by itself workss:
SELECT
SUM(CAST([Convo] AS DECIMAL(10,2)))
FROM [a2hr].[dbo].[FinalPayroll] where period = 18
September 23, 2021 at 5:16 pm
Welp then start adding columns one by one until it breaks 🙂
September 23, 2021 at 5:20 pm
OK my bad... got it... it was the extra parenthesis:
SELECT
SUM(CAST([Convo] AS DECIMAL(10,2)))
,SUM(CAST([F9D2] AS DECIMAL(10,2)))
,SUM(CAST([F9D5] AS DECIMAL(10,2)))
,SUM(CAST([F9DMTM] AS DECIMAL(10,2)))
,SUM(CAST([Exception] AS DECIMAL(10,2)))
,SUM(CAST([Training] AS DECIMAL(10,2)))
,SUM(CAST([TOTAL Time] AS DECIMAL(10,2)))
FROM [a2hr].[dbo].[FinalPayroll] where period = 18
September 23, 2021 at 5:32 pm
Welp then start adding columns one by one until it breaks 🙂
Good lesson on basic troubleshooting. Sorry I almost screwed that all up with my post about desk checking.
--Jeff Moden
Change is inevitable... Change for the better is not.
November 8, 2021 at 8:08 pm
This was removed by the editor as SPAM
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply