Teradata SQL - TRYCAST / TRY_CAST Function

access_time 7 months ago visibility243 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 at 22 days 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

Kontext Column

Created for everyone to publish data, programming and cloud related articles.
Follow three steps to create your columns.

Learn more arrow_forward

More from Kontext

local_offer teradata local_offer SQL

visibility 708
thumb_up 0
access_time 11 months ago

This code snippet shows how to calculate time differences.

local_offer teradata local_offer teradata-utilities

visibility 33
thumb_up 0
access_time 17 days 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 ...

local_offer teradata local_offer SQL local_offer teradata-functions

visibility 10
thumb_up 0
access_time 22 days ago

Teradata LPAD function is used to add repeated characters at the beginning of a string to increase the string to a specified length. It can be used to add leading space or zeros to a string. LPAD(source_string, length, fill_string) Returns the source_string padded to the left with the ...

About column

Code snippets for various programming languages/frameworks.

rss_feed Subscribe RSS