I have the following SQL query that is returning a result of 92.967013425802
and I need it to be formatted like 93%
and add the percent sign. I have tried changing the sum to round but I received an error
The function 'round' is not a valid windowing function, and cannot be used with the OVER clause.
My query:
select
count(*) * 100.0 / sum(count(*)) over()
from
db_table_MetaData
group by
MetaValue
order by
MetaValue
Any help would be appreciated.
In essence you take the 08/15 ROUND() function to get your numeric value. After this you cast it into a nvarchar(x) and add a string to your string.
The SQL LIKE Operator The percent sign (%) represents zero, one, or multiple characters. The underscore sign (_) represents one, single character.
The percent ("P") format specifier multiplies a number by 100 and converts it to a string that represents a percentage. Show activity on this post. If 2 decimal places is your level of precision, then a "smallint" would handle this in the smallest space (2-bytes). You store the percent multiplied by 100.
select
--Cast(Round(count(*) * 100.0 / sum(count(*)), 0) as nvarchar(5) + '%'
CAST(Round(count(*) * 100.0 / sum(count(*)), 0) as nvarchar(5)) + '%'
from
db_table_MetaData
This should do the trick.
In essence you take the 08/15 ROUND()
function to get your numeric value. After this you cast it into a nvarchar(x)
and add a string to your string. However I have no method of checking my syntax right now.
Strange you got not a valid function. Perhaps you didn't provide the correct parameters?
This worked for me.
select cast(Round('92.967013425802', 0) as nvarchar(10)) + '%'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With