I have two columns in a SQL table, fooId (int) and fooName (varchar).
Is there a way to select them both as one column with a space between them?
select fooId + ' ' + fooName as fooEntity
from mytable
They’re different types so I’m getting an error.
This field will be databound directly in a control in the web app.
SQL Server 2008
(I’m a bit of a sql beginner)
String concatenation is different between databases, so it helps to know which database because you need to know:
SQL Server doesn’t do implicit conversion of numeric into string values:
…so you need to use CAST (or CONVERT) to explicitly change the data type to a text based data type.
For Oracle & PostgreSQL, use the double pipe to concatenate strings:
For MySQL, you can use the CONCAT function: