Trim Leading or/and Trailing Zeros in Teradata

access_time 7 months ago visibility1155 comment 0

In SQL Server, there are functions like TRIM, LTRIM, RTRIM to remove characters from a string. In Teradata, the equivalent is TRIM function.

Trim from leading zeros

The following code snippets remove leading zeros from the string literal.

select trim(leading '0' from '00012345000')

Result:

Trim(LEADING '0' FROM '00012345000')

1 12345000

Trim from trailing zeros

Similarly, TRIM function can also be used to remove trailing zeros:
select trim(trailing '0' from '00012345000')

Result:

Trim(TRAILING '0' FROM '00012345000')

1 00012345

Trim both leading and trailing zeros

select trim(both '0' from '00012345000')
Result:
Trim(BOTH '0' FROM '00012345000')
1 12345

Trim a column in a view or table

select trim(leading '0' from column_name) from table_name
select trim(trailing '0' from column_name) from table_name
select trim(both '0' from column_name) from table_name

Trim other characters

You can use TRIM function to trim all other characters by replacing '0' to the character you want to trim. 

select trim(leading 'A' from 'AAA2041145')
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 9
thumb_up 0
access_time 30 days ago

Teradata AMPs are the parallel distributed storage and computing unit in a Teradata server. We can use HASHAMP function to calculate the total AMP count in a Teradata system. HASHAMP function HASHAMP function returns the identification number of the primary AMP corresponding to the specified ...

visibility 1155
thumb_up 0
access_time 7 months ago

This page shows how to trim or remove leading or/and trailing zeros using Teradata SQL.

visibility 43513
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 ...