SQL SELECT 多列合二为一

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13466190/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 12:12:11  来源:igfitidea点击:

SQL SELECT multiple columns into one

sqlsql-server-2008select

提问by Mario M

I have this query in SQL Server 2008:

我在 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?

我怎样才能得到这个结果?

采纳答案by Justin

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

回答by John Woo

just use ' '

只是使用 ' '

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