You will need to cast or convert as a CHAR datatype, there is no varchar datatype that you can cast/convert data to:

select CAST(id as CHAR(50)) as col1 
from t9;

select CONVERT(id, CHAR(50)) as colI1 
from t9;

See the following 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;

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,type)

or

 CONVERT(expr USING transcoding_name)

Your original query had the syntax backwards.

Answer from Taryn on Stack Overflow
๐ŸŒ
W3Schools
w3schools.com โ€บ sql โ€บ func_sqlserver_cast.asp
SQL Server CAST() Function
The CAST() function converts a value (of any type) into a specified datatype. Tip: Also look at the CONVERT() function. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: ...
Discussions

Cast to VarChar Without Knowing the Length โ€“ SQLServerCentral Forums
It won't. Cast doesn't do anything special to set the size of varchar and varchar defaults ... Sorry, i didn't read thouroughly. I thought they were just numbers and dates. Ronald San Juan | SQL DBA ID 710124 ~ Code "Northwind" More on sqlservercentral.com
๐ŸŒ sqlservercentral.com
November 2, 2007
Best practice : converting INT to VARCHAR
What are your opinions on converting INT (and indeed anything else like GUIDs) to VARCHAR? For INTs I see the following used SELECT MyINT, ']'+CAST(MyINT as varchar(20))+'[' AS [Cast], ']'+CONVERT(varchar(20),MyINT)+'[' AS [Convert()], ']'+STR(MyINT,20)+'[' AS [Str()], ']'+LTRIM(STR(MyINT,20))+'[' ... More on forums.sqlteam.com
๐ŸŒ forums.sqlteam.com
0
0
August 6, 2015
type conversion - How to retain same FLOAT value after converting it to a VARCHAR in Azure Synapse - Database Administrators Stack Exchange
What I want is the displayed values to be the same, however it seems Azure Synapse is rounding the number when the CAST is performed. I need this to work inline as I am hashing several concatenated values and need these all COALESCED VARCHARS. More on dba.stackexchange.com
๐ŸŒ dba.stackexchange.com
Convert INT to Varchar in a case statement
You can put single quotes around it like '992', or CAST(992 AS VARCHAR(4)). More on reddit.com
๐ŸŒ r/SQL
3
3
February 13, 2023
๐ŸŒ
Microsoft Learn
learn.microsoft.com โ€บ en-us โ€บ sql โ€บ t-sql โ€บ functions โ€บ cast-and-convert-transact-sql
CAST and CONVERT (Transact-SQL) - SQL Server | Microsoft Learn
For more information, see Collation Precedence (Transact-SQL). To assign a different collation to the output, apply the COLLATE clause to the result expression of the CAST or CONVERT function. For example: SELECT CAST('abc' AS varchar(5)) COLLATE French_CS_AS;
๐ŸŒ
SQLServerCentral
sqlservercentral.com โ€บ forums โ€บ topic โ€บ cast-to-varchar-without-knowing-the-length
Cast to VarChar Without Knowing the Length โ€“ SQLServerCentral Forums
November 2, 2007 - It won't. Cast doesn't do anything special to set the size of varchar and varchar defaults ... Sorry, i didn't read thouroughly. I thought they were just numbers and dates. Ronald San Juan | SQL DBA ID 710124 ~ Code "Northwind"
๐ŸŒ
DB Vis
dbvis.com โ€บ thetable โ€บ sql-convert-the-handbook-of-data-conversion-in-sql-2
SQL CONVERT: The Handbook of Data Conversion in SQL
May 2, 2024 - It is specific to certain database management systems, such as Microsoft SQL Server, MySQL, Sybase, and (partially) Oracle. Many SQL data types can be converted to others using CONVERT, but there are some restrictions. Compatibility depends on the specific database system, and some conversions may result in loss of accuracy or data truncation. That is why SQL Server offers a complete data type conversion table. Both SQL CONVERT and CAST functions can be used for data type conversion, but they differ in syntax and usage.
๐ŸŒ
SQLTeam
forums.sqlteam.com โ€บ transact-sql
Best practice : converting INT to VARCHAR - Transact-SQL - SQLTeam.com Forums
August 6, 2015 - For INTs I see the following used SELECT MyINT, ']'+CAST(MyINT as varchar(20))+'[' AS [Cast], ']'+CONVERT(varchar(20),MyINT)+'[' AS [Convert()], ']'+STR(MyINT,20)+'[' AS [Str()], ']'+LTRIM(STR(MyINT,20))+'[' ...
Find elsewhere
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ sql โ€บ convert-int-to-varchar-sql
Convert INT to VARCHAR SQL - GeeksforGeeks
July 23, 2025 - The employee_id column is converted to VARCHAR using the CAST method. The AS VARCHAR(10) indicates that a maximum of 10 characters may be included in the resulting VARCHAR column.
๐ŸŒ
Mimo
mimo.org โ€บ glossary โ€บ sql โ€บ cast-function
SQL CAST() Function: Syntax, Usage, and Examples
Use CAST(column AS VARCHAR(n)) to convert values into readable strings. Be mindful of the maximum length (n), or your values might get cut off. ... Use this for creating identifiers or output formatting. In SQL Server, you can cast datetime to a string, but you may also prefer CONVERT for format ...
๐ŸŒ
Django
docs.djangoproject.com โ€บ en โ€บ 6.0 โ€บ ref โ€บ models โ€บ fields
Model field reference | Django documentation | Django
Support for unlimited VARCHAR columns was added on SQLite. ... Optional. The database collation name of the field. ... Collation names are not standardized. As such, this will not be portable across multiple database backends.
๐ŸŒ
Oracle
docs.oracle.com โ€บ javadb โ€บ 10.8.3.0 โ€บ ref โ€บ rrefsqlj33562.html
CAST function
SELECT CAST (miles AS INT) FROM Flights -- convert timestamps to text INSERT INTO mytable (text_column) VALUES (CAST (CURRENT_TIMESTAMP AS VARCHAR(100))) -- you must cast NULL as a data type to use it SELECT airline FROM Airlines UNION ALL VALUES (CAST (NULL AS CHAR(2))) -- cast a double as ...
๐ŸŒ
Anytimecode
anytimecode.com โ€บ SQL โ€บ ConversionFunctions
SQL SERVER- Conversion Functions
SELECT CAST( 9.2 AS INTEGER) AS [CAST] Output : CONVERT: Similar to CAST, COVERT also explicitly converts an expression from one data type to another. SYNTAX: CONVERT ( data type , expression [, style] ) EXAMPLE 1: Query: SELECT CONVERT(VARCHAR(30 ), GETDATE()) AS [Default Style] Output : EXAMPLE 2: Query: SELECT CONVERT(VARCHAR(30 ), GETDATE(), 1) AS [Without Century] Output : EXAMPLE 3: Query: SELECT CONVERT(VARCHAR(30 ), GETDATE(), 101) AS [With Century] Output : Copyright ยฉ 2014-2026 Ranji Rajan All Rights Reserved | Disclaimer | Contact Me | About
๐ŸŒ
Databricks
kb.databricks.com โ€บ delta โ€บ unable-to-cast-string-to-varchar
Unable to cast string to varchar - Databricks
May 10, 2022 - You cannot cast string to varchar, but you can create a varchar Delta table. %sql CREATE OR REPLACE TABLE delta_varchar_table2 (`col1` VARCHAR(1000)) USING DELTA; Use SHOW TABLE on the newly created table and it reports a varchartype. ... You can now create another varchar Delta table, based ...
๐ŸŒ
dbt
docs.getdbt.com โ€บ sql-reference โ€บ cast
Working with the SQL CAST function
5 days ago - Executing this function in a SELECT statement will return the column you specified as the newly specified data type. Analytics engineers will typically be casting fields to more appropriate or useful numeric, strings, and date types. You may additionally use the CAST function in WHERE clauses and in joins. Below, weโ€™ll walk through a practical example using the CAST function.
๐ŸŒ
W3Schools
w3schools.com โ€บ sql โ€บ sql_create_table.asp
SQL CREATE TABLE Statement
SQL Examples SQL Editor SQL Quiz SQL Exercises SQL Server SQL Syllabus SQL Study Plan SQL Bootcamp SQL Certificate SQL Training ... The CREATE TABLE statement is used to create a new table in a database. CREATE TABLE table_name ( column1 datatype constraint, column2 datatype constraint, column3 datatype constraint, .... ); The table_name parameter specifies the name of the new table. The column1, column2, ... parameters specify the names of the columns within the table. The datatype parameter specifies the data type of each column (e.g. varchar, int, date, etc.).
๐ŸŒ
DevArt
blog.devart.com โ€บ home โ€บ products โ€บ sql server tools โ€บ sql server cast function with examples for data type conversion
SQL CAST Function in SQL Server โ€“ Syntax, Examples, and Best Practices
October 17, 2025 - SELECT CAST('Devart CAST Function' AS VARCHAR(5)) AS ShortString; -- Output: Devar ยท In this case, only the first five characters are kept, and the rest is lost. The following table shows how the exact input string behaves when cast with different lengths: Length defines both accuracy and performance. To keep queries efficient and data consistent, apply these rules: Always specify a length so you donโ€™t rely on SQL Server defaults.
๐ŸŒ
Snowflake Documentation
docs.snowflake.com โ€บ en โ€บ sql-reference โ€บ functions โ€บ to_char
TO_CHAR , TO_VARCHAR | Snowflake Documentation
+-------------------------------------------------+ | TO_VARCHAR('03-APRIL-2024'::DATE, 'YYYY.MM.DD') | |-------------------------------------------------| | 2024.04.03 | +-------------------------------------------------+
๐ŸŒ
TypeORM
typeorm.io
TypeORM - Code with Confidence. Query with Power. | TypeORM
Works with MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, MongoDB, and more.
๐ŸŒ
MySQL
dev.mysql.com โ€บ doc โ€บ en โ€บ cast-functions.html
MySQL :: MySQL 8.4 Reference Manual :: 14.10 Cast Functions and Operators
For a description of how casting to BINARY affects comparisons, see Section 13.3.3, โ€œThe BINARY and VARBINARY Typesโ€. ... Produces a string with the VARCHAR data type, unless the expression expr is empty (zero length), in which case the result type is CHAR(0).
๐ŸŒ
Microsoft Learn
learn.microsoft.com โ€บ en-us โ€บ sql โ€บ t-sql โ€บ data-types โ€บ char-and-varchar-transact-sql
char and varchar (Transact-SQL) - SQL Server | Microsoft Learn
When n isn't specified in a data definition or variable declaration statement, the default length is 1. If n isn't specified when using the CAST and CONVERT functions, the default length is 30. Objects that use char or varchar are assigned the default collation of the database, unless a specific ...