คุณจะต้องcastหรือconvertเป็นCHARประเภทข้อมูลไม่มีvarcharประเภทข้อมูลที่คุณสามารถส่ง / แปลงข้อมูลเป็น:
select CAST(id as CHAR(50)) as col1
from t9;
select CONVERT(id, CHAR(50)) as colI1
from t9;
ดู SQL ต่อไปนี้ - ในการดำเนินการที่SQL Fiddle :
/*! Build Schema */
create table t9 (id INT, name VARCHAR(55));
insert into t9 (id, name) values (2, 'bob');
/*! SQL Queries */
select CAST(id as CHAR(50)) as col1 from t9;
select CONVERT(id, CHAR(50)) as colI1 from t9;
นอกจากข้อเท็จจริงที่ว่าคุณกำลังพยายามแปลงเป็นประเภทข้อมูลที่ไม่ถูกต้องไวยากรณ์ที่คุณใช้convertนั้นไม่ถูกต้อง convertฟังก์ชั่นใช้ต่อไปนี้ที่exprเป็นคอลัมน์หรือค่าของคุณ:
CONVERT(expr,type)
หรือ
CONVERT(expr USING transcoding_name)
ข้อความค้นหาเดิมของคุณมีไวยากรณ์ย้อนหลัง