Solved

Exporting Mysql resutlts into one colunm

Posted on 2011-02-24
7
281 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
  • 4
  • 2
7 Comments
 
LVL 39

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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how the fundamental information of how to create a table.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now