×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• 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.

# 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.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:

Field 1 = PDN
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.

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:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!