Search code examples
sqlstring-concatenation

In SQL, how to concatenate string with integer data type column


I am trying to add string "Rs" with amount column. The data type of amount is integer. But Sql is not allowing me to concatenate string with int data type column.Image 1

Image 2


Solution

  • You need to explicitly convert the int to varchar before concatenating with any string

    select 'RS'+cast(total_amount as varchar(100)),*
    from yourtable
    

    If you are sql server 2012+ then use CONCAT which does implicit conversion

    select Concat('RS',total_amount),*
    from yourtable