您需要将cast
或convert
作为CHAR
数据类型,没有varchar
数据类型可以将数据转换为:
select CAST(id as CHAR(50)) as col1
from t9;
select CONVERT(id, CHAR(50)) as colI1
from t9;
请参见以下SQL-in-action-over at 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)
Your 或iginal query had the syntax backwards.