Teradata SQL - TRYCAST / TRY_CAST Function

access_time 11 months ago visibility423 comment 0

In SQL Server, TRY_CAST function returns a value cast to a specified data type is the cast is successful or null is the cast is not successful.  In Teradata, the equivalent function is TRYCAST.

Code snippets

-- return int 1030
SELECT TRYCAST('01030' AS int);
-- return 2019-01-01 as it is a valid date string 
-- return null 
SELECT TRYCAST('-128' AS byteint);
SELECT TRYCAST('127' AS byteint);
-- return null as overflow
SELECT TRYCAST('128' AS byteint);


In SQL Server, the first argument can be any valid expression while in Teradata, it needs to be CHAR or VARCHAR.

Teradata TRY_CAST


Teradata CAST test

info Last modified by Administrator 5 months ago copyright This page is subject to Site terms.
Like this article?
Share on

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts

More from Kontext

visibility 43500
thumb_up 0
access_time 6 years ago

SELECT is one of the most commonly used statements. In this tutorial, I will cover the following items: Two of the principal query clauses—FROM and SELECT Data Types Built-in functions CASE expressions and variations like ISNULL and COALESCE. * The function names mentioned above are ...

visibility 565
thumb_up 0
access_time 5 months ago

TPT (Teradata Parallel Transporter) is a client suit that support multiple instances of data extracting, loading, and updating functions in a scalable, high-speed, parallel-processing environment. It utilize other client tools like FastLoad, FastExport, MultiLoad, etc.  It is written with Java ...

visibility 3392
thumb_up 0
access_time 4 years ago

For many SQL Server or Oracle developers, you may encounter some inconveniences when writing SQL queries. For example, how to select from dummy table or local defined variables. This page summarize the equivalents in Teradata SQL.