Search code examples
sql-server-2008rdbms

select with varchar and int, money value in table


I wrote below query:

SELECT Name, salary + ',' + Branch + ' , ' + PhNumber AS address 
FROM tablename;

my error is : Cannot convert a char value to money. The char value has incorrect syntax.

How to solve it?


Solution

  • Your column salary is of datatype: money and, column PhNumber is of type: numeric. And you are trying to concatenate it with char column: Branch.

    Need to Cast it as:

    SELECT Name, CAST(salary as VARCHAR(20)) + ',' + Branch + ' , ' 
                + CAST(PhNumber as VARCHAR(20)) AS address 
    FROM tablename;