KLR
KLR

Reputation: 61

Having trouble adding + '%' in sql server - get error message "Error converting data type varchar to numeric"

Here is my line of query where I am getting error msg 8114, level 16, state 5. I have the sum and rounding exactly as I need it - just can't get the + '%' part to work:

SUM(CAST(ROUND(ENROLLMENT,1) AS DECIMAL (10,2)))/SUM(CAST(ROUND(CAPACITY,1) AS DECIMAL (10,2))) *100 + '%' AS 'fill rate %'

Any help will be appreciated!

Upvotes: 0

Views: 42

Answers (1)

xQbert
xQbert

Reputation: 35323

Either cast your decimal to varchar

cast(SUM(CAST(ROUND(ENROLLMENT,1) AS DECIMAL (10,2)))/SUM(CAST(ROUND(CAPACITY,1) AS DECIMAL (10,2))) *100 as varchar(100)) + '%' AS 'fill rate %'

or simply don't add the %. The column header already say's it's a % field...

cast(SUM(CAST(ROUND(ENROLLMENT,1) AS DECIMAL (10,2)))/SUM(CAST(ROUND(CAPACITY,1) AS DECIMAL (10,2))) *100 as varchar(100)) AS 'fill rate %'

Or wherever you're displaying this have the display add the '%'to the right of the field displaying the decimal value.

Upvotes: 1

Related Questions