I have below query and need to cast
create table t9 (id int, name varchar (55));
insert into t9( id, name)values(2, 'bob');
select CAST(id as VARCHAR(50)) as col1 from t9;
select CONVERT(VARCHAR(50),id) as colI1 from t9;
select CAST(id as CHAR(50)) as col1 from t9; select CONVERT(id, CHAR(50)) as colI1 from t9;
See SQL Fiddle with Demo.
Besides the fact that you were trying to convert to an incorrect datatype, the syntax that you were using for
convert was incorrect. The
convert function uses the following where
expr is your column or value:
CONVERT(expr USING transcoding_name)
Your original query had the syntax backwards.