access_time 2 years ago languageEnglish
more_vert

Teradata SQL - TRYCAST / TRY_CAST Function

visibility 632 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 
SELECT TRYCAST('2019-01-01' AS DATE);
-- return null 
SELECT TRYCAST('2019-13-32' AS DATE);
SELECT TRYCAST('-128' AS byteint);
SELECT TRYCAST('127' AS byteint);
-- return null as overflow
SELECT TRYCAST('128' AS byteint);

Note

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 TRY_CONVERT

Teradata CAST test

info Last modified by Administrator 8 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 969
thumb_up 0
access_time 8 months ago
visibility 686
thumb_up 0
access_time 8 months ago
visibility 49
thumb_up 0
access_time 4 months ago