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

  • SEARCH
  • Home
  • 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 8555299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:05:34+00:00 2026-06-11T15:05:34+00:00

I am working in Teradata with some descriptive data that needs to be transformed

  • 0

I am working in Teradata with some descriptive data that needs to be transformed from a gerneric varchar(60) into the different field lengths based on the type of data element and the attribute value. So I need to take whatever is in the Varchar(60) and based on field ‘ABCD’ act on field ‘XYZ’. In this case XYZ is a varchar(3). To do this I am using CASE logic within my select. What I want to do is

eliminate all occurances of non alphabet/numeric data. All I want left are upper case Alpha chars and numbers.
In this case “Where abcd = ‘GROUP’ then xyz should come out as a ‘000’, ‘002’, ‘A’, ‘C’
eliminate extra padding
Shift everything Right

        abcd    xyz
1   GROUP   NULL
2   GROUP   $
3   GROUP   000000000000000000000000000000000000000000000000000000000000
4   GROUP   000000000000000000000000000000000000000000000000000000000002
5   GROUP   A
6   GROUP   C
7   GROUP   r

To do this I have tried TRIM and SUBSTR amongst several other things that did not work. I have pasted what I have working now, but I am not reliably working through the data within the select. I am really looking for some options on how to better work with strings in Teradata. I have been working out of the “SQL Functions, Operators, Expressions and Predicates” online PDF. Is there a better reference. We are on TD 13

SELECT abcd
        , CASE 
            -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
            WHEN abcd= 'GROUP'
                THEN(
                    CASE
                        WHEN SUBSTR(tx.abcd,60, 4) = 0
                            THEN (
                                    SUBSTR(tx.abcd,60, 3)
                                        )
                            ELSE
                                TRIM (TRAILING FROM tx.abcd)
                        END
                        )
            END AS abcd

FROM db.descr tx
WHERE tx.abcd IS IN ( 'GROUP')

The end result should look like this

    abcd    xyz
1   GROUP   000
2   GROUP   002
3   GROUP     A
4   GROUP     C

I will have to deal with approx 60 different “abcd” types, but they should all conform to the type of data I am currently seeing.. ie.. mixed case, non numeric, non alphabet, padded, etc..

I know there is a better way, but I have come in several circles trying to figure this out over the weekend and need a little push in the right direction.

Thanks in advance,
Pat

  • 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-11T15:05:35+00:00Added an answer on June 11, 2026 at 3:05 pm

    The SQL below uses the CHARACTER_LENGTH function to first determine if there is a need to perform what amounts to a RIGHT(tx.xyz, 3) using the native functions in Teradata 13.x. I think this may accomplish what you are looking to do. I hope I have not misinterpreted your explanation:

    SELECT CASE WHEN tx.abcd = 'GROUP'
                 AND CHARACTER_LENGTH(TRIM(BOTH FROM tx.xyz) > 3
                THEN SUBSTRING(tx.xyz FROM (CHARACTER_LENGTH(TRIM(BOTH FROM tx.xyz)) - 3))
                ELSE tx.abcd
           END
    FROM db.descr tx;
    

    EDIT: Fixed parenthesis in SUBSTRING

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working on game where plates will be falling from top to bottom. Some plates
Working with an .asp application that connects and displays data cleanly. Problem occurs with
Working with phoneGap implementing drawing with Canvas. The catch we've run into is that
Working with an undisclosed API, I found a function that can set the number
Working on calling a C function from my asm project. I'm trying to push
Working on an extension that use the new experimental devtools apis. How do you
Working sample using one Table SELECT t.* FROM ( SELECT TITLE.name, (TITLE.value-TITLE.msp) AS Lower,
Working with a Lucene index, I have a standard document format that looks something
working on xcode I realized that if I create a non-void method, I call
Working on an app using Akka 2 deployed with Play-mini. I pulled logback into

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.