converting int to data type numeric.
Your SQL code is more then a bit wrong.
numeric(5, 5) means a total size of 5 digits and 5 decimal place = not leading digit before decimal; that can't work.
Use numeric(5,0) or better numeric(10, 5).
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi,
I am trying to return a percentage number - the max values I am working with is 10,000
My code is
case when tt.[Under £20] <> 0 then
( CAST(tt.[Under £20] as numeric(5,5)) /CAST(tt.Total as numeric(5,5))*100) else 0
end as '%',
Can anyone help?
Thanks
converting int to data type numeric.
Your SQL code is more then a bit wrong.
numeric(5, 5) means a total size of 5 digits and 5 decimal place = not leading digit before decimal; that can't work.
Use numeric(5,0) or better numeric(10, 5).
Don't use numeric 5,5, use something like numeric(12,2) Or alternatively let SQL Server do conversion for you and just round the result, e.g.
cast(case when tt.[Under £20] <> 0 then
(tt.[Under £20]*1.0 /tt.Total)*100) else 0
end) as numeric(10,2)) as '%',