Reputation: 21
I have this SQL view query.
SUM('ValueFC') AS VALUEFC_0 .....
........
SUM(g.AMTCUR_0 * g.SNS_0 * - 1) AS 'ValueFC',
Whenever I run it it says " Operand data type varchar is invalid for sum operator"
Upvotes: 0
Views: 2334
Reputation: 21
After changind it like this
SUM(CAST('ValueFC' AS INT)) AS VALUEFC_0,
The error now says "Conversion failed when converting varchar value 'VALUEFC' to data int
Upvotes: 0
Reputation: 93694
In SUM('ValueFC')
aggregate the 'ValueFC'
will be considered as string since it enclosed with single quotes so the error.
Since it as alias name in sub-select
or derived query
you can use the name directly in sum aggregate to pull the values like
SUM(ValueFC) AS VALUEFC_0 .....
........
SUM(g.AMTCUR_0 * g.SNS_0 * - 1) AS 'ValueFC',
Upvotes: 1