Solved

Exporting Mysql resutlts into one colunm

Posted on 2011-02-24
7
289 Views
Last Modified: 2012-05-11
i have results sets like this:
customre  historytext
123           this is an example line, this is another example line, this is the third example line.

What i would like is this

Customer  historytext                           historytext                               historytext
123           this is an example line         this is aother example line         this is the third example line



So that every time on my org example, when there is a comma in the history text, it would move this text into the next cell.
I do not want to write the code usiing the MAX is null expression, as i don't know how many colunmss could be on any one customer, they all vary

Is this possible.

I am using Mysql and had been using the Group_concat function to group all text into one cell.
however when i export it this data will not all show on the cell because of the limits on excel.

Can anyone please help?
0
Comment
Question by:Putoch
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 40

Accepted Solution

by:
lcohan earned 250 total points
ID: 34971072
What is the datatype on the three concatenated columns? It is pretty obvious they are big enough to create a new column something like text perhaps and obviously EXCEL cell won't allow that. Did you tried to export to flat CSV file instead which is different than XLS or XLSX?
0
 

Author Comment

by:Putoch
ID: 34971440
I tried exporting to CSV but it changes the format of the file and dliminates the text into rows , i have tried to stop this but can not.
The history_text is a mix of 3 actual fields from the db.
They are a timestamp  & varchar data types.

SELECT customer_id, Group_Concat(date_entered,' : ',enteredby,' : ',history_text, ' // ')as HISTORY
FROM ....

0
 

Author Comment

by:Putoch
ID: 34971483
When i export it to csv it exports it into rows instead of into colunms
0
Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

 

Expert Comment

by:dbadmin78
ID: 34973230
Try this:

SELECT customer_id,rtrim(convert(char,date_entered))+','+rtrim(convert(char,enteredby))+','+rtrim(convert(char,history_text))+',' as HISTORY

from yourtablename

I think Excel doesn't see the colon as a delimiter...If that works and you need help with the date format, I have more code for that :)
0
 

Assisted Solution

by:dbadmin78
dbadmin78 earned 250 total points
ID: 34973253
Also, if you do need to keep using the GROUP_CONCAT feature, can you add a comma after the colon like so:

SELECT customer_id, Group_Concat(date_entered,' :, ',enteredby,' :, ',history_text, ' // ')as HISTORY
FROM ....


Excel will read the comma as a delimeter and it won't put it in the text.
0
 

Author Comment

by:Putoch
ID: 35084128
It was on the configuration section of the SQLYOG export tool.

Escaped by: \
Lines Terminated by: \n

Fields
Variable Lenghts
Fields Terminated by: ,


When i reconfigured the settings it worked out perfectly.
0
 

Author Closing Comment

by:Putoch
ID: 35084139
thanks everyone for their advice
I believe the following solved the problem:
It was on the configuration section of the SQLYOG export tool.

Escaped by: \
Lines Terminated by: \n

Fields
Variable Lenghts
Fields Terminated by: ,


When i reconfigured the settings it worked out perfectly.
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have a large data set and a SSIS package. How can I load this file in multi threading?
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question