Mario
Mario

Reputation: 14780

SQL SELECT multiple columns into one

I have this query in SQL Server 2008:

SELECT Id, Year, Manufacturer, Model  
FROM Table

and I need something like this...

SELECT Id, (Year + [space] + Manufacturer + [space] + Model) AS MyColumn 
FROM Table

How can I get this result?

Upvotes: 9

Views: 52024

Answers (2)

Justin
Justin

Reputation: 9724

I think all integer or numeric data types you need convert to String data type. When you can create your new column.

Query:

SELECT Id, (Cast([Year] as varchar(4)) + ' ' + Manufacturer + ' ' + Model) AS MyColumn 
FROM   Tablename

Upvotes: 9

John Woo
John Woo

Reputation: 263723

just use ' '

SELECT Id, ([Year] + ' ' + Manufacturer + ' ' + Model) AS MyColumn 
FROM   Tablename

Upvotes: 8

Related Questions