Convert Numeric value to Varchar

2019-03-24 16:11发布

问题:

i m trying to fetch the record using append some alphabt in my numeric column. but i m getting error, i tried with cast and convert function.

for exmaple

select convert(varchar(10),StandardCost +'S')
from DimProduct where ProductKey = 212

here StandardCost is a numeric field, but when i fetch the record i m getting error please have a look.

回答1:

i think it should be

select convert(varchar(10),StandardCost) +'S' from DimProduct where ProductKey = 212

or

select cast(StandardCost as varchar(10)) + 'S' from DimProduct where ProductKey = 212


回答2:

First convert the numeric value then add the 'S':

 select convert(varchar(10),StandardCost) +'S'
 from DimProduct where ProductKey = 212