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

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


Chris,

That is just what I needed--it works perfectly.

Thank you

Joe

-----Original Message-----
From: Mackin, Christopher <CMackin at quiznos.com>
To: dba-sqlserver at databaseadvisors.com <dba-sqlserver at databaseadvisors.com>
Date: Friday, September 24, 2004 4:26 PM
Subject: RE: [dba-SQLServer] Problem concatening a string and a numeric


|Unlike Access, the conversion between Numeric and String values needs to be
done explicitly in T-SQL.
|
|Use this:
|
|SELECT 'abc' + CAST(lngCompID AS VarChar(100))...........
|
|Chris Mackin
|
|
|-----Original Message-----
|From: dba-sqlserver-bounces at databaseadvisors.com
|[mailto:dba-sqlserver-bounces at databaseadvisors.com]On Behalf Of Joseph
|O'Connell
|Sent: Friday, September 24, 2004 3:04 PM
|To: dba-sqlserver at databaseadvisors.com
|Subject: [dba-SQLServer] Problem concatening a string and a numeric
|
|
|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
|
|
|_______________________________________________
|dba-SQLServer mailing list
|dba-SQLServer at databaseadvisors.com
|http://databaseadvisors.com/mailman/listinfo/dba-sqlserver
|http://www.databaseadvisors.com
|
|_______________________________________________
|dba-SQLServer mailing list
|dba-SQLServer at databaseadvisors.com
|http://databaseadvisors.com/mailman/listinfo/dba-sqlserver
|http://www.databaseadvisors.com
|





More information about the dba-SQLServer mailing list