Praveen k. Agrawal
Praveen k. Agrawal

Reputation: 449

Convert Numeric value to Varchar

I'm trying to fetch the records and append some letters to my numeric column, but I'm getting an error. I tried with cast and convert function.

For example:

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

here StandardCost is a numeric field, but when I fetch the record I get an error.

Upvotes: 23

Views: 191494

Answers (2)

MayureshP
MayureshP

Reputation: 2634

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

Upvotes: 41

Ocaso Protal
Ocaso Protal

Reputation: 20237

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

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

Upvotes: 8

Related Questions