?
Solved

Replace line breaks with a space with using Select.. Into Outfile

Posted on 2008-10-20
5
Medium Priority
?
561 Views
Last Modified: 2012-05-05
I am running a query to download a csv. Some of the fields might contain line breaks, which makes the program reading the file think that the record has ended, messing up the column count. Can I replace the breaks with a space or make it ignore the breaks?
SELECT 
					p.prodid,
					r.id,
					r.rganum,
					p.partnum,
					p.description,
					p.mfgmonth,
					p.mfgyear,
					p.produse,
					p.lot,
					p.amount,
					p.unitMeasure
			INTO OUTFILE '$file2' 
			FIELDS TERMINATED BY ';' 
			LINES TERMINATED BY '\n' 
			FROM 
				ns_rgaproduct p,
				ns_rga r
			WHERE 
				r.status = 'approved' 
				and r.decdate >= '$exportdate'
				and r.id = p.rgaid

Open in new window

0
Comment
Question by:nisupport
[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
  • 3
  • 2
5 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 2000 total points
ID: 22758120
try:
SELECT 
                              p.prodid,
                              r.id,
                              r.rganum,
                              p.partnum,
                              REPLACE(`p`.`description`,'\n',''),
                              p.mfgmonth,
                              p.mfgyear,
                              p.produse,
                              p.lot,
                              p.amount,
                              p.unitMeasure
                  INTO OUTFILE '$file2' 
                  FIELDS TERMINATED BY ';' 
                  LINES TERMINATED BY '\n' 
                  FROM 
                        ns_rgaproduct p,
                        ns_rga r
                  WHERE 
                        r.status = 'approved' 
                        and r.decdate >= '$exportdate'
                        and r.id = p.rgaid

Open in new window

0
 

Author Comment

by:nisupport
ID: 22759129
I am still getting the same results. Is there another character for a break to replace? I have tried <br>.
0
 
LVL 82

Expert Comment

by:hielo
ID: 22759331
Other than '\n', you can try:
'\r\n'

NOTE:You need to use the replace on every field that may potentially have the newline.
0
 

Author Comment

by:nisupport
ID: 22759371
Figured it out needed to put '\r\n' for the line break.
0
 
LVL 82

Expert Comment

by:hielo
ID: 22759720
glad to help
0

Featured Post

7 Extremely Useful Linux Commands for Beginners

Just getting started with Linux? Here's a quick start guide that has 7 commands that we believe will come in handy.

Question has a verified solution.

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

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

770 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