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
🌐
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

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
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
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
How do I parse a String into java.sql.Date format?

Can't your SQL server accept strings for dates? The ones I've used can, so I just do something like:

String sqlDate = new SimpleDateFormat("yyyy-MM-dd").format(new SimpleDateFormat("dd-MM-yyyy").parse(startDate));

... and pass sqlDate to the parametrized query. Like konrad mentioned, lowercase 'mm' is for minutes, and uppercase 'MM' is for month, so I think that's where your problem was.

More on reddit.com
🌐 r/java
5
1
March 27, 2012
🌐
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 ...
🌐
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....
🌐
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
January 24, 2026 - 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.
🌐
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.
🌐
dbt
docs.getdbt.com › sql-reference › cast
Working with the SQL CAST function - dbt Docs
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.
Find elsewhere
🌐
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.
🌐
TutorialsTeacher
tutorialsteacher.com › sqlserver › cast-function
SQL Server CAST() Function: Convert DataType
It is used with the Salary column which is of integer type and converts it to string value. ... In the following example, the CAST() function gives an error while converting a string to an int.
🌐
MySQL
dev.mysql.com › doc › 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.
🌐
MariaDB
mariadb.com › docs › server › reference › sql-functions › string-functions › cast
CAST | Server | MariaDB Documentation
February 6, 2026 - The main difference between CAST and CONVERT() is that CONVERT(expr,type) is ODBC syntax, while CAST(expr as type) and CONVERT(... USING ...) are SQL92 syntax. To cast a value to a string data type while specifying the character set, use this extended syntax: See the examples for casting to character sets.
🌐
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.
🌐
GeeksforGeeks
geeksforgeeks.org › sql server › sql-server-cast-function
SQL Server CAST() Function - GeeksforGeeks
February 3, 2026 - The CAST() function is used to convert a value from one data type to another, helping SQL Server work with data in the required format. It is useful when we need to: Change strings to numbers for calculations.
🌐
Oracle
docs.oracle.com › javadb › 10.8.3.0 › ref › rrefsqlj33562.html
CAST function
In this discussion, the Derby SQL-92 data types are categorized as follows: ... A BOOLEAN value can be cast explicitly to any of the string types. The result is 'true', 'false', or null. Conversely, string types can be cast to BOOLEAN. However, an error is raised if the string value is not 'true', 'false', 'unknown', or null.
🌐
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.
🌐
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))
🌐
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.
🌐
W3Schools
w3schools.com › sql › func_mysql_cast.asp
MySQL 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 ...