HOW TO

Cast a number to a string using SQL

Last Published: April 25, 2020

Summary

In some scenarios (such as using select by attributes or a definition query) a string operation might be necessary, but if the data is a number type it does not work. This article provides a sample of how to cast the number field to a string for a SQL operation.

Procedure

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. This example selects the fields that are not identical between a text field and a number field:

CAST( "SQLNUM"  AS CHARACTER(12)) <> "SQLTEXT"

    Article ID:000011922

    Software:
    • ArcMap

    Receive notifications and find solutions for new or common issues

    Get summarized answers and video solutions from our new AI chatbot.

    Download the Esri Support App

    Related Information

    Discover more on this topic

    Get help from ArcGIS experts

    Contact technical support

    Download the Esri Support App

    Go to download options