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.
Converting int to string / varchar using Convert() This Convert() in SQL Server is also a conversion function used to convert a value of one data type to another.
So what is varchar in SQL? As the name suggests, varchar means character data that is varying. Also known as Variable Character, it is an indeterminate length string data type. It can hold numbers, letters and special characters.
The CONVERT() function converts a value (of any type) into a specified datatype.
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
First convert the numeric value then add the 'S'
:
select convert(varchar(10),StandardCost) +'S' from DimProduct where ProductKey = 212
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With