[dba-SQLServer] Problem concatening a string and a numeric

Joseph O'Connell joconnell at indy.rr.com
Fri Sep 24 16:03:43 CDT 2004


A field in a table contains integer values.  How do I create a SQL statement
that will prefix the values with a string?
For example, if the field values are
     1
     2
     3

I wish to return
   abc1
   abc2
   abc3

"SELECT 'abc' + lngCompID AS ModifiedValue FROM dbo.tblCompany"
generates an error message:
"Syntax error converting the varchar value 'abc' to a column of data type
int"

"SELECT 'abc' + Cstr(lngCompID) AS ModifiedValue FROM dbo.tblCompany"
generates an error message:
"'Cstr' is not a recognized function name"


Joe O'Connell





More information about the dba-SQLServer mailing list