Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combining multiple related data items into one record

Status
Not open for further replies.

AkutaSame

Programmer
Oct 5, 2002
97
US
Not a simple task as far as I can figure, I am trying to take rows of data, based on whether or not the "OwnerID" field has content and merge the "Comments" fields. I'm not really finding the words that I need to describe the question, so I have written up an example. The "Row#" is not actually a field, but the SQL row numbers (much more there for visuals than the actual data issue). The data came from a proprietary database format, which I have had to export into a text file. I have done some text manipulation, turned the file from plaintext content (which the proprietary database exported containing spaces to "align" everything) into comma delimited files, splitting up certain fields (like full name into first and lastname fields), and importing this information into Excel (to do some more data modification before importing into SQL). I am currently working with an 80+MB Excel document, which horribly has a Comments field that spans over multiple rows (because of the way the information was output from the original database). Thus, the issue at hand. Not all Comments fields span multiple rows, only the ones that contain more information than there was room on the original database's text field.

Here is my logic:
If current row does not have content in the OwnerID field, merge the Comments field of current row with the Comment field of the previous row, else move to next row.

Example: (Data may not appear correctly due to HTML limitations)
Row# OwnerID Comments
1 26576 Example 1
2 7544 Example
3 2
4 Example 2
5 4732 Example 3
6 4731 Example
7 4
8 2634 Example
9 5

Will become:

Row# OwnerID Comments
1 26576 Example 1
2 7544 Example 2 Example 2
3 4732 Example 3
4 4731 Example 4
5 2634 Example 5
 
The solution might be related to a solution described by nigelrivett which uses the COALESCE function.

See

Thread183-695743



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top