วันพุธที่ 17 ธันวาคม พ.ศ. 2557

คำสั่ง SQL CONCAT

คำสั่ง SQL CONCAT

เป็นคำสั่งที่ใช้สำหรับการระบุเงื่อนไขการเลือกข้อมูลในตาราง (Table) โดยทำการรวมข้อความเข้าด้วยกัน

Database : MySQL,Microsoft Access,SQL Server,Oracle

Syntax
SELECT CONCAT(Culumn1,Culumn2,...) AS [New-Field] FROM [Table-Name]

Table : customer

CustomerID
Name
Email
CountryCode
Budget
Used
C001
Win Weerachaiwin.weerachai@thaicreate.com
TH
1000000600000
C002
John Smithjohn.smith@thaicreate.com
EN
2000000800000
C003
Jame Bornjame.born@thaicreate.com
US
3000000600000
C004
Chalee Angelchalee.angel@thaicreate.com
US
4000000100000
Sample1 การเลือกข้อมูลโดยทำการรวมฟิวด์ CustomerID,Name,Email
SELECT CustomerID,CONCAT(CustomerID,Name,Email) AS ConcatField FROM customer

Output 
CustomerID
ConcatField
C001
C001Win Weerachaiwin.weerachai@thaicreate.com
C002
C002John Smithjohn.smith@thaicreate.com
C003
C003Jame Bornjame.smith@thaicreate.com
C004
C004Chalee Angelchalee.angel@thaicreate.com


ไม่มีความคิดเห็น:

แสดงความคิดเห็น