All-caps is literal text, lower-case is something into which you should interpolate a value:

CAST(expression AS CHAR)
-- or:
CAST(expression AS VARCHAR)

You can optionally specify a length.

Unfortunately, it's a bit harder with datetimes, if you want to format it in any way that's different from the default representation.

My info came from the MSDN site. I think you'll have to read that site, and others, carefully and play around with it a bit, but hopefully the CAST function will be a good start.

Good luck!

Answer from Platinum Azure on Stack Overflow
🌐
Microsoft Learn
learn.microsoft.com › en-us › sql › t-sql › data-types › tostring-database-engine
ToString (Database Engine) - SQL Server | Microsoft Learn
November 18, 2025 - ToString is called implicitly when a conversion from hierarchyid to a string type occurs. Acts as the opposite of Parse (Database Engine). -- Transact-SQL syntax node.ToString ( ) -- This is functionally equivalent to the following syntax -- which implicitly calls ToString(): CAST(node AS nvarchar(4000))
🌐
W3Schools
w3schools.com › sql › func_sqlserver_cast.asp
SQL Server CAST() Function
String Functions: ASCII CHAR_LENGTH ... BIN BINARY CASE CAST COALESCE CONNECTION_ID CONV CONVERT CURRENT_USER DATABASE IF IFNULL ISNULL LAST_INSERT_ID NULLIF SESSION_USER SYSTEM_USER USER VERSION SQL Server Functions · String Functions: ASCII CHAR CHARINDEX CONCAT Concat ...
Discussions

sql server 2005 - tsql : best way to cast variables to string type? - Stack Overflow
CREATE FUNCTION QuoteNull ( @InputStr ... RETURN @String END ... I do not think there is--and if there were, I wouldn't trust it, as there'd probably be very little control over the overall formatting. Build your own, and it'll look exactly as it needs to look. Factors to contemplate: ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... I’m Jody, the Chief Product and Technology Officer at Stack Overflow. Let’s... 1 SQL Syntax: Casting a datatype ... More on stackoverflow.com
🌐 stackoverflow.com
Cast vs convert?
As a general rule, use CAST for as much as you can. It’s ANSI standard SQL so will work even if you move away from SQL Server. CONVERT on the other hand is SQL Server specific. More on reddit.com
🌐 r/SQL
18
3
March 29, 2024
Can someone explain CAST() to me?
It's used to convert from one data type to another. Why do I sometimes need to use it (for timestamps mainly) and sometimes I dont It varies depending on the exact SQL version you're using, but sometimes certain types of implicit conversions can be made without explicit casting required. But in general it's good practice to cast even when you can get away with not doing so. More on reddit.com
🌐 r/SQL
9
6
March 22, 2024
How do I convert these values (currently String) into INT (but with a catch)
Cast(case when value like ‘%>%’ then 600 else value end) as int More on reddit.com
🌐 r/SQL
9
16
February 12, 2022
🌐
StrataScratch
stratascratch.com › blog › what-are-the-steps-to-cast-int-in-sql-for-type-conversion
What Are the Steps to Cast INT in SQL for Type Conversion? - StrataScratch
July 5, 2024 - In PostgreSQL, you can use a shorthand for CAST(), which is a double colon (::). ... The SQL Server users might also want to use CONVERT(). It has a very similar, the-other-way-round syntax.
🌐
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
If you try an incorrect conversion, ... letters to an int, SQL Server returns an error message. When the CAST or CONVERT functions output a character string, and they receive a character string input, the output has the same collation and collation label as the input....
Find elsewhere
🌐
W3Schools
w3schools.com › sql › sql_case.asp
SQL CASE Expression
String Functions: ASCII CHAR_LENGTH ... BIN BINARY CASE CAST COALESCE CONNECTION_ID CONV CONVERT CURRENT_USER DATABASE IF IFNULL ISNULL LAST_INSERT_ID NULLIF SESSION_USER SYSTEM_USER USER VERSION SQL Server Functions · String Functions: ASCII CHAR CHARINDEX CONCAT Concat ...
🌐
Medium
medium.com › @kp9810113 › ending-the-sql-syntax-war-why-google-bet-big-on-zetasql-8e5bea0de516
Ending The SQL Syntax War: Why Google Bet Big On ZetaSQL | by The Concurrent Mind | Feb, 2026 | Medium
1 month ago - One engine treats a function name as standard. Another engine requires a different name. One engine happily casts a string into a number. Another refuses. A third accepts the cast, but changes the execution plan so badly that your cloud bill looks like a prank. So you end up writing defensive SQL.
🌐
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 ...
🌐
Oracle
docs.oracle.com › en › database › oracle › oracle-database › 18 › sqlrf › REPLACE.html
SQL Language Reference
January 4, 2023 - Both search_string and replacement_string, as well as char, can be any of the data types CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB. The string returned is in the same character set as char.
🌐
MySQL
dev.mysql.com › doc › refman › 8.4 › en › cast-functions.html
MySQL :: MySQL 8.4 Reference Manual :: 14.10 Cast Functions and Operators
Like CHAR, but produces a string with the national character set. See Section 12.3.7, “The National Character Set”. Unlike CHAR, NCHAR does not permit trailing character set information to be specified. ... Produces a result of type REAL. This is actually FLOAT if the REAL_AS_FLOAT SQL mode is enabled; otherwise the result is of type DOUBLE. ... Produces a signed BIGINT value. ... CAST() and CONVERT() support casting geometry values from one spatial type to another, for certain combinations of spatial types.
🌐
DB Vis
dbvis.com › thetable › sql-cast-function-everything-you-need-to-know
SQL CAST Function: Everything You Need to Know
April 5, 2024 - This is why you may need to cast an integer to a string in SQL. Achieve that with the following MySQL query: ... Awesome! You are now a CAST SQL expert! Here is a list of best practices for the CAST function in SQL: Convert data only when required as cast operations can lead to overhead, data loss, and inaccurate results.
🌐
dbt
docs.getdbt.com › sql-reference › cast
Working with the SQL CAST function
6 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.
🌐
StrataScratch
stratascratch.com › blog › data-type-conversion-in-sql-closer-look-at-cast-function
Data Type Conversion in SQL: A Closer Look at CAST Function - StrataScratch
May 10, 2024 - CAST() is a standard SQL function for explicit data type conversion. By allowing you to specify the output data type, it puts you in control of data shaping. The CAST() syntax is very straightforward.
🌐
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.
🌐
Esri Support
support.esri.com › en-us › knowledge-base › cast-a-number-to-a-string-using-sql-1462482852682-000011922
How To: Cast a Number to a String Using SQL
October 1, 2025 - This code casts the number field "SQLNUM" as a text field, which can then be used in a text operation. CAST( "SQLNUM" AS CHARACTER(12)) The following is an example of how it can be implemented to combine a text field and an number field in a SQL operation.
🌐
Databricks
docs.databricks.com › reference › sql language reference › functions › built-in functions › alphabetical list of built-in functions › cast function
cast function | Databricks on AWS
Each sourceFieldName of type STRING is cast to targetKeyType and mapped to a map key. Each source field value of sourceFieldType is cast targetValueType and mapped the respective map value.
🌐
RudderStack
rudderstack.com › guides › how-to-sql-type-casting
SQL type casting: How to Get Started? | RudderStack
... Regarding the supported representation styles, MS SQL Server offers a quite large variety as shown in the following table. Regarding the conversion of a string into a numeric data type such as int and float, cast is the suitable function.
🌐
InterSystems
docs.intersystems.com › irislatest › csp › docbook › DocBook.UI.Page.cls
CAST (SQL) | InterSystems SQL Reference | InterSystems IRIS Data Platform 2025.3
If you specify a CAST with an unsupported data type, InterSystems IRIS® issues an SQLCODE -376. CAST(expression AS [CHAR | CHARACTER | VARCHAR | NCHAR | NVARCHAR]) converts a numeric or string expression to a character string data type.