22

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.

Patrick McDonald
  • 64,141
  • 14
  • 108
  • 120
Praveen k. Agrawal
  • 439
  • 1
  • 5
  • 15
  • If you post code, XML or data samples, **please** highlight those lines in the text editor and click on the "code samples" button ( `{ }` ) on the editor toolbar to nicely format and syntax highlight it! – marc_s Mar 16 '11 at 09:44

2 Answers2

40

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
Ash Burlaczenko
  • 24,778
  • 15
  • 68
  • 99
MayureshP
  • 2,514
  • 6
  • 31
  • 41
8

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

 select convert(varchar(10),StandardCost) +'S'
 from DimProduct where ProductKey = 212
Ocaso Protal
  • 19,362
  • 8
  • 76
  • 83