Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

MS SQL data - strange character but no show in the actual table when submitting a form

Posted on 2006-06-26
10
Medium Priority
?
690 Views
Last Modified: 2008-07-02
I have a form which submits data to an MSSQL table.  This table then submits to our backend system.

There is a problem only at certain times with the data submitting to the backend.  In MSSQL, it shows nothing.  When I copy the data over to textpad or wordpad to view the records, I see something very strange.

First of all, we do a check and take out all weird characters before we submit to MSSQL - including !@#$%^&*()_+=-,./<>?;':"[]\{}| etc.

Then we enter the form into mssql table.

In the table, all looks well.

When I extract the files to a text document, this is what I see for the normal submissions:

BILL          1 address       city   state    zip

**********
for the ones that come across and cause errors in our backend system, this is what I see in text editor:

BILL         "1 Address
"               city           state            zip

Does anyone know what causes this and what I can do to eliminate the problem?

0
Comment
Question by:foreverdita
  • 3
  • 2
  • 2
  • +2
10 Comments
 
LVL 25

Expert Comment

by:dstanley9
ID: 16984734
Check for carriage returns (CHR(13)) and line feeds (CHR(10)) in your text.  Some text editors will show a single CR or LF, some will only show if they are together (CRLF) - this is Windows style.
0
 
LVL 28

Expert Comment

by:imran_fast
ID: 16984762
In Query Analyzer select the column from the table and check the accii code for that character
ascii('a)' and try to replace this ascii with empty string

But obviously it is coming from one of the client machine so you have to identify that client machine and then  check for regional setting for that client machine.
0
 

Author Comment

by:foreverdita
ID: 16984901
How would I check for carriage returns by sleecting * from table where Ad1 has a carriage return?  In query Analyzer I mean?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:foreverdita
ID: 16984910
select * from address where ad1 has a carraige return (how do I check for carriage return here)

 
0
 
LVL 4

Expert Comment

by:kenpem
ID: 16984918
In your weird-character check, you should also remove anything below CHAR(32) as these are all non-printable control characters. Possibly everything above CHAR(126) as well. This should render everything neatly viewable.
0
 
LVL 4

Assisted Solution

by:kenpem
kenpem earned 400 total points
ID: 16984940
SELECT * FROM address WHERE ad1 LIKE ('%'+CHAR(13)+'%')

will show you which records contain a carriage return. Also check for CHAR(10) for line-feeds.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 16985968
>>Possibly everything above CHAR(126) as well. <<
Ouch!  You have just knocked out Latin America and most of Europe.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 16986000
>>Does anyone know what causes this and what I can do to eliminate the problem?<<
It means you have a CrLf or Cr at the end of the Address column.  This is easy to confirm:
1. Open the table in Enterprise Manager
2. Select the row that is causing the problem.
3. Go into Edit mode (F2) and the value should disappear (it is actually there, you are just on the second line).  On other cells when pressing F2 you will see the value highlighted and you will remain on the same line.
0
 

Author Comment

by:foreverdita
ID: 16986672
OK, then upon a form submittal, how would I get rid of the CHAR(13) before submitting the contents of the form?

theaddress = replace(ad1, ""+Char(13)+"", "")

Or something like that?

Also, is there a way to replace existing records in the table that have char13 without erasing the entire ad1?
0
 
LVL 25

Accepted Solution

by:
dstanley9 earned 1600 total points
ID: 16986822
To fix existing records:

UPDATE address
SET ad1 = REPLACE(ad1,CHAR(13),'')

To fix on the form:

theaddress = ad1.Replace( "\n", "");  // CHR(10)
or
theaddress = ad1.Replace( "\r", "");   // CHR(13)
or
theaddress = ad1.Replace( "\r\n", "");  //CHR(13)+CHR(10)

depending on which character(s) is causing the problem.
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

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

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…
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 ?
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to shrink a transaction log file down to a reasonable size.

927 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