(Turn) How to combine two or more columns into one? Combine multiple field values or multiple records

Reprinted from:

http://blog.sina.com.cn/s/blog_640b84590101cfg4.html

 

Today I need to deal with a small data problem, which involves querying the sql database by the way.

Requirements: Combine several fields of different types into one field.
The query I use is:
select hanyi+liju+xiangguanci from Content;
Query error message: The operator is invalid for the data type. The operator is add and the type is ntext.
This is because you used the + sign as the string concatenator, and the data type of my field is ntext.
The + sign can only be used for ordinary addition and subtraction in sql. String connectors have different methods in different databases.
In mysql, use concat(str1,str2,...). 
example:
SELECT CONCAT('My', 'S', 'QL');
Result: MySQL
Oracle uses the || sign.
select 'abc' || 'def' from dual; 
result: adbdef
 
Typically, we concatenate data obtained from different fields. Each repository provides methods for this purpose:
MySQL: CONCAT()
Oracle: CONCAT(), ||
SQL Server: +
 
In fact, for non-programmers, we can use excel or access to get it.
It can be achieved in the excel sheet: D1=concatenate(a1,b1,c1); or D1= A1&B1&C1.
In access, D=[A]&[B]&[C]

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326666401&siteId=291194637