access_time 2 years ago languageEnglish
more_vert

Teradata SQL - TRYCAST / TRY_CAST Function

visibility 835 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 11 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 298
thumb_up 0
access_time 7 months ago
visibility 1652
thumb_up 0
access_time 2 years ago
visibility 435
thumb_up 0
access_time 11 months ago