Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7807803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:58:06+00:00 2026-06-02T02:58:06+00:00

In Teradata DB I have source table create set table SRC_TABLE ( Some_Id varchar(2O)

  • 0

In Teradata DB I have source table

create set table SRC_TABLE (
    Some_Id varchar(2O) not null
);

This table is loaded with data from external system. I have target table

create set table DST_TABLE (
    Some_Id decimal(4,0) not null
);

I need to copy rows from SRC_TABLE to DST_TABLE safely. There is a contract in place that external system will provide only values convertible to DECIMAL(4). However, is there any safe way how to select rows in SRC_TABLE which are not compliant with contract and may cause typecasting failure?

Update: I cannot use UDF functions due to restrictions in environment I am working in.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T02:58:09+00:00Added an answer on June 2, 2026 at 2:58 am

    Finally with help of my colleagues I came to feasible solution. It has some limitations (sign is not considered, decimal part is not considered), but for IDs it works just fine.

    1. Trim spaces from both beginning and end of string
    2. Trim leading zeros from string
    3. Test for maximum allowed length
    4. Pad string with zeros to four chars (add four zeros to beginning of string and get last four characters from string)
    5. Test each position in string on set of allowed chars

    So the records from SRC_TABLE which cannot be converted to DECIMAL(4) can be obtained by select:

    select 
      Some_Id
    from
      SRC_TABLE
    where
      characters(trim(leading '0' from trim(both ' ' from Some_Id))) > 4
      or substring(substring('0000' || trim(leading '0' from trim(both ' ' from Some_Id)) FROM characters('0000' || trim(leading '0' from trim(both ' ' from Some_Id))) - 3) FROM 1 FOR 1) NOT IN ('0','1','2','3','4','5','6','7','8','9')  
      or substring(substring('0000' || trim(leading '0' from trim(both ' ' from Some_Id)) FROM characters('0000' || trim(leading '0' from trim(both ' ' from Some_Id))) - 3) FROM 2 FOR 1) NOT IN ('0','1','2','3','4','5','6','7','8','9')
      or substring(substring('0000' || trim(leading '0' from trim(both ' ' from Some_Id)) FROM characters('0000' || trim(leading '0' from trim(both ' ' from Some_Id))) - 3) FROM 3 FOR 1) NOT IN ('0','1','2','3','4','5','6','7','8','9')
      or substring(substring('0000' || trim(leading '0' from trim(both ' ' from Some_Id)) FROM characters('0000' || trim(leading '0' from trim(both ' ' from Some_Id))) - 3) FROM 4 FOR 1) NOT IN ('0','1','2','3','4','5','6','7','8','9');
    

    EDIT:
    More convenient is the way suggested by dnoeth in his answer to Convert char to int TeraData Sql , which also works in TD 13.10:

    -- TO_NUMBER returns NULL when failing
    
    CAST(TO_NUMBER(UTENTE_CD) AS INTEGER)
    
    -- check if there are only digits
    CASE WHEN UTENTE_CD  = ''                     -- all spaces
           THEN NULL
         WHEN LTRIM(UTENTE_CD, '0123456789') = '' -- only digits
           THEN CAST(UTENTE_CD AS INTEGER)
         ELSE NULL
    END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to insert the data from an excel sheet into a teradata table.
I have a table full of data called MYTABLE I used SELECT * FROM
I'm converting SQL from Teradata to SQL Server in Teradata, they have the format
I have two tables in a teradata database that look like this accounts account_number
Few months back I saw TeraData Express Edition. I have no idea of this
This is in teradata. For many good reasons, I would like to have a
can you extract data from teradata on ibm z/os as an XML document? i
I have a REXX job that needs to read from both Teradata (using BTEQ)
I am working on a request where I have to create a table to
When loading tables from SAS to Teradata, SAS loads the data (usually using the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.