Solved

Forcing a new line

Posted on 2002-05-21
12
1,025 Views
Last Modified: 2008-03-06
I am looking for a way in an SQL statement to force a new line in a varchar field.
0
Comment
Question by:Garfy
[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
  • 6
  • 5
12 Comments
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 100 total points
ID: 7025863
Try concatenating CHAR(10) where you want the new line, for example:

SELECT SUBSTRING(varchar_col, 1, 5) + CHAR(10) + SUBSTRING(varchar_col, 6, 10)
FROM ...

Or

SELECT varchar_col1 + CHAR(10) + varchar_col2
FROM ...

etc..
0
 
LVL 1

Expert Comment

by:falconew
ID: 7025880
ping
0
 
LVL 1

Author Comment

by:Garfy
ID: 7026183
Sorry I should have said before but I am trying to insert a string with compulsory line breaks between words..

Eg.

"Annual General Meeting held on 1/1/2000 at 2:00pm at Henry's place"

Should go in like
"Annual General Meeting
 held on 1/1/2000
 at 2:00pm at Henry's place"
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 1

Author Comment

by:Garfy
ID: 7026256
CHAR(10) puts in an unknown character...

here is the first part of the SQL statement using Scott's answer

Update [Company]
SET
 [Comments] = 'Regular meeting date : BI MONTHLY '
+ CHAR(10)
+ 'Meeting time : 1.30PM '
+ CHAR(10)
+ 'Meeting place : Otway Community Services '
+ CHAR(10)
+ 'Annual General Meeting: '
+ CHAR(10)
+ '03091997 '
+ CHAR(10)
+ 'at 1.00PM '
+ CHAR(10)
+ 'at SENIOR CITIZENS HALL'
0
 
LVL 1

Expert Comment

by:falconew
ID: 7026341
what do you mean char(10) puts in an unknown character?
Why do you want to force a new line in a varchar field?
If I know your requirement, probably we can find another way to solve the problem.

Regards
0
 
LVL 1

Author Comment

by:Garfy
ID: 7028517
I am trying to force the varchar field to have multiple lines but where I want them.  That way when I bring them into a Crystal Report they will be formatted properly.  I cannot extend the database to include more fields and I want to make the report do as little work as possible.  The original data was brought across from an AS400.  But when it was brought across they forgot the AGM data.  The meeting data was brought across though and it has been placed in multiple lines in the way that I am trying to achieve with the AGM data.  I know I can press Ctrl Enter on the database, but I am automating the system (as there are many records) by using VB.  Hence the requirement for an SQL statement.

Also, when I use Char(10) or Char(13) SQL (2000) puts in a little square box instead of a line break, meaning it does not recognise the character.
0
 
LVL 1

Expert Comment

by:falconew
ID: 7028650
When I query the table in query analyzer which contain the char(10) it show up correctly. The square box appear when the result viewed in grid.
I think it depends on the query tools to recognize the character.
Is it a problem when you run it on crystal report using this character?
0
 
LVL 1

Author Comment

by:Garfy
ID: 7036277
hmmm, older data that was brought across from the AS400 has forced line breaks that you cannot see but can see the effect of in the grid of SQL.  The square character does not give me the effect of a new line...
0
 
LVL 1

Expert Comment

by:falconew
ID: 7036296
Yes, the square character does not give the effect in the grid of SQL. But it has an effect when you set the query analyzer to text instead of grid.
Do you mean grid in SQL analyzer or grid control in VB?
0
 
LVL 1

Author Comment

by:Garfy
ID: 7037911
Grid in SQL Server....  after opening the table and viewing all rows...
0
 
LVL 1

Expert Comment

by:falconew
ID: 7038355
why don't give a try using the Query analyzer and set it to the text display instead of the grid..
0
 
LVL 1

Author Comment

by:Garfy
ID: 7038406
Finally got it to work...  thanks....
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

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 maintenance plan 8 53
find SQL job run average duration 24 54
SQL Rewrite without the NULLIF 4 25
How come this XML node is not read? 3 27
Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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.

740 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