INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

SQL for Parsing a String Delimited with Periods

SQL for Parsing a String Delimited with Periods

(OP)
Hi all...

In a TERADATA table, I have the following data stored in a field called DIRECTORY:

PDN.RAD.40391.0110.IA0
PDN.SW.69740.HDQ.IWB1
OMH.WDW.216942.Standard.119988
DCHH.HH.44463.OB.RR

I need to separate the characters between the periods into separate fields.  

Can anyone help?

Thanks!

Ezekiel

RE: SQL for Parsing a String Delimited with Periods

(OP)
One more thing...

I only need the first three entries...

Example:

PDN.RAD.40391.0110.IA0

Field 1 = PDN
Field 2 = RAD
Field 3 = 40391

Thanks,

Ezekiel

RE: SQL for Parsing a String Delimited with Periods

if it were a flat file you could load it as a delimited file. Not sure if you can do this table to table or table to file to table.  other than that, you basically need to find the position of the first 3 periods and then you can use a substring funtion to pull out the first 3 values.

I'd start with something like the code below.  I'm 99.9% sure that the syntax, etc. is off, but I think you'll get the idea.   best of luck - brian
SELECT
    POSITION(COLUMNX,',' AS PERIOD1
    ,POSITION(SUBSTR(COLUMNX,PERIOD1+1),100,',') AS PERIOD2
    ,POSITION(SUBSTR(COLUMNX,PERIOD2+1),100,',') AS PERIOD3
    ,SUBSTR(COLUMNX,1,PERIOD1-1) AS FIELD1
    ,SUBSTR(COLUMNX,PERIOD1+1,PERIOD2-PERIOD1-1) AS FIELD2
    ,SUBSTR(COLUMNX,PERIOD2+1,PERIOD3-PERIOD2-PERIOD1-1) AS FIELD3

RE: SQL for Parsing a String Delimited with Periods

You can use "derived columns"... :

select    'ABC.DEF.GHI.JKL.MNO'    as MYCOLUMN
    ,    substring(MYCOLUMN from 1 for (position('.' in MYCOLUMN) (named POSDOT1)) - 1)    as FIELD1
    ,    substring((substring(MYCOLUMN from POSDOT1 + 1) (named SUB1)) from 1 for (position('.' in SUB1) (named POSDOT2)) - 1)    as FIELD2
    ,    substring((substring(SUB1 from POSDOT2 + 1) (named SUB2)) from 1 for (position('.' in SUB2) (named POSDOT3)) - 1)    as FIELD3

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close