Q
Problem solve Get help with specific problems with your technologies, process and projects.

Combine multiple lines of text into one

I have a table that I created from a flat file. I have thousands of records. What is my best approach to normalize this? I would like to keep the multiple lines of text, but put them into one field.

Hello, I have a table that I created from a flat file. Not very normalized as you can see:

ID    TEXT
--    ----
1     This is just
1     some sample text
1     that I am using
2     Here is some
2     more of it
3     and yet some more

I have thousands of records. What is my best approach to normalize this into ..

ID    TEXT
--    ----
1     This is just
      some sample text
      that I am using
2     Here is some
      more of it
3     and yet some more

I would like to keep the multiple lines of text, but put them into one field. Please help. Thanks.

There are two approaches you could try. First is to pre-process your flat file before loading. Simple idea, yes?

The second approach is to concatenate the multiple lines into one using a GROUP BY query with a special function for this purpose. MySQL has the GROUP_CONCAT function, Sybase ASA has the LIST function, and there may be similar functions in other databases. Check under aggregate functions in your documentation.

There's another way, which is to write a stored procedure using a cursor, but that's far more difficult than the first approach.

This was last published in September 2006

Dig Deeper on Oracle and SQL

PRO+

Content

Find more PRO+ content and other member only offers, here.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide.com

SearchDataCenter

SearchContentManagement

SearchFinancialApplications

Close