Solved

Exporting Mysql resutlts into one colunm

Posted on 2011-02-24
7
287 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 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Server Results to Excel File 18 73
Operational reporting on a OLTP vs Data Warehouse reporting 4 26
SQL Query Syntax error after > 11 39
Related to SQL Query 5 17
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

679 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