Reputation: 1
a.taxamount
is between 0.0
and 20.0
, and I would like to display it as 0.0%
or 120.0%
but I am getting a conversion error.
SELECT....
,(a.taxamount * 100) + '%' AS TaxAmount
Upvotes: 0
Views: 214
Reputation: 788
Try the following query.
SELECT CAST((a.taxamount * 100) AS VARCHAR(10))+ '%' AS TaxAmount
Upvotes: 0
Reputation: 453067
The +
operator is used both for addition and concatenation. If you mix strings and numbers addition is assumed and it tries to implicitly cast the string to a number.
As you are on SQL Server 2008 you should convert the number to varchar
first before concatenating.
CAST(a.taxamount * 100 AS VARCHAR(10)) + '%'
On more recent versions you could use the CONCAT
function that does this implicitly or use FORMAT(a.taxamount, 'P1')
to multiply by 100 and append the percent character.
Upvotes: 4