กวดวิชาSQL

SQL HOME บทนำ SQL ไวยากรณ์ SQL SQL Select SQL Select Distinct SQL ที่ไหน SQL และหรือไม่ใช่ คำสั่ง SQL โดย SQL แทรกลงใน ค่าว่างของ SQL SQL Update SQL Delete SQL Select Top SQL Min และ Max SQL Count, Avg, Sum SQL Like SQL Wildcards SQL ใน SQL ระหว่าง นามแฝงของ SQL การรวม SQL SQL Inner Join SQL เข้าร่วมด้านซ้าย SQL Right Join SQL เข้าร่วมแบบเต็ม เข้าร่วมด้วยตนเองของ SQL SQL Union กลุ่ม SQL โดย SQL มี SQL Exists SQL ใด ๆ ทั้งหมด SQL Select Into แทรก SQL ลงใน Select กรณี SQL ฟังก์ชัน SQL Null กระบวนงานที่เก็บไว้ของ SQL ข้อคิดเห็นของ SQL ตัวดำเนินการ SQL

ฐานข้อมูลSQL

SQL สร้าง DB SQL Drop DB ฐานข้อมูลสำรองของ SQL SQL สร้างตาราง SQL Drop Table SQL Alter Table ข้อจำกัดของ SQL SQL ไม่ใช่ Null SQL Unique คีย์หลักของ SQL คีย์ต่างประเทศของ SQL SQL Check SQL Default ดัชนี SQL SQL Auto Increment SQL Dates มุมมอง SQL การฉีด SQL SQL Hosting ประเภทข้อมูล SQL

การอ้างอิงSQL

คีย์เวิร์ด SQL ฟังก์ชัน MySQL ฟังก์ชันเซิร์ฟเวอร์ SQL ฟังก์ชัน MS Access SQL Quick Ref

ตัวอย่างSQL

ตัวอย่าง SQL แบบทดสอบ SQL แบบฝึกหัด SQL ใบรับรอง SQL

ฟังก์ชันการแปลงเซิร์ฟเวอร์ SQL ()

❮ ฟังก์ชันเซิร์ฟเวอร์ SQL

ตัวอย่าง

แปลงนิพจน์เป็น int:

SELECT CONVERT(int, 25.65);

ความหมายและการใช้งาน

ฟังก์ชัน CONVERT() จะแปลงค่า (ประเภทใดก็ได้) เป็นประเภทข้อมูลที่ระบุ

เคล็ดลับ:ดู ฟังก์ชันCAST() ด้วย

ไวยากรณ์

CONVERT(data_type(length), expression, style)

ค่าพารามิเตอร์

Value Description
data_type Required. The datatype to convert expression to. Can be one of the following: bigint, int, smallint, tinyint, bit, decimal, numeric, money, smallmoney, float, real, datetime, smalldatetime, char, varchar, text, nchar, nvarchar, ntext, binary, varbinary, or image
(length) Optional. The length of the resulting data type (for char, varchar, nchar, nvarchar, binary and varbinary)
expression Required. The value to convert to another data type
style Optional. The format used to convert between data types, such as a date or string format. Can be one of the following values:

Converting datetime to character:
Without century With century Input/Output Standard
0100mon dd yyyy hh:miAM/PMDefault
1101mm/dd/yyyy US
2102 yyyy.mm.ddANSI
3103 dd/mm/yyyyBritish/French
4104dd.mm.yyyyGerman
5105 dd-mm-yyyyItalian
6106dd mon yyyy-
7107Mon dd, yyyy-
8108hh:mm:ss-
9109mon dd yyyy hh:mi:ss:mmmAM (or PM)Default + millisec
10110mm-dd-yyyyUSA
11111 yyyy/mm/ddJapan
12112 yyyymmddISO
13113dd mon yyyy hh:mi:ss:mmm Europe (24 hour clock)>
14114hh:mi:ss:mmm24 hour clock
20120yyyy-mm-dd hh:mi:ssODBC canonical (24 hour clock)
21121yyyy-mm-dd hh:mi:ss.mmmODBC canonical (24 hour clock)
 126yyyy-mm-ddThh:mi:ss.mmmISO8601
 127yyyy-mm-ddThh:mi:ss.mmmZISO8601 (with time zone Z)
 130dd mon yyyy hh:mi:ss:mmmAMHijiri
 131dd/mm/yy hh:mi:ss:mmmAMHijiri
Converting float to real:
Value Explanation
0Maximum 6 digits (default)
18 digits
216 digits
Converting money to character:
Value Explanation
0No comma delimiters, 2 digits to the right of decimal
1Comma delimiters, 2 digits to the right of decimal
2 No comma delimiters, 4 digits to the right of decimal

รายละเอียดทางเทคนิค

ทำงานใน: SQL Server (เริ่มตั้งแต่ปี 2008), ฐานข้อมูล Azure SQL, Azure SQL Data Warehouse, Parallel Data Warehouse

ตัวอย่างเพิ่มเติม

ตัวอย่าง

แปลงนิพจน์จากประเภทข้อมูลหนึ่งเป็นอีกประเภทหนึ่ง (varchar):

SELECT CONVERT(varchar, 25.65);

ตัวอย่าง

แปลงนิพจน์จากประเภทข้อมูลหนึ่งเป็นอีกประเภทหนึ่ง (วันที่และเวลา):

SELECT CONVERT(datetime, '2017-08-25');

ตัวอย่าง

แปลงนิพจน์จากประเภทข้อมูลหนึ่งเป็นอีกประเภทหนึ่ง (varchar):

SELECT CONVERT(varchar, '2017-08-25', 101);

❮ ฟังก์ชันเซิร์ฟเวอร์ SQL