Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 10th, 2004, 11:46 AM
Authorized User
 
Join Date: Dec 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default Searching for a carriage return in a text field

Somehow a user was able to enter a CR/LF into a text field in one of my tables. I'd like to be able to search the rest of the records to see if this has happened before, but I'm not sure of the syntax I'd have to use. Can anyone enlighten me ?

Also does anyone have any idea on how to prevent a CR/LF from being inserted into a database ? I'm using VB as a front end/SQL Server as the back end.
 
Old March 10th, 2004, 01:02 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

With SQL Server you can use the CHARINDEX and CHAR functions:
Code:
SELECT * FROM yourtable
WHERE CHARINDEX(CHAR(13)+CHAR(10),yourcolumn)>0;
will find strings which contain CR/LF.

You should prevent the inclusion of these 'bad' characters in your client code. If your requirements dictate that a string may not contain CR/LF, then this is an enforcement of a business rule which is best handled at the client.

If you use a stored procedure to do your updates, you could also search any input string parameter using code similar to the CHARINDEX snippet above and SUBSTRING out the CR/LF. Languages like T/SQL aren't very efficient doing character string manipulation, so this is better handled at the client, IMO.

Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
 
Old March 10th, 2004, 03:53 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dear levinll:

This also works:

Code:
SELECT * FROM TableToSearch WHERE ColumnToSearch LIKE('%'+char(13)+char(10)+'%')
Rand
 
Old March 10th, 2004, 04:00 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here's the VB code to get rid of CR/LF in a string:

Code:
Replace(StringToSearch, Chr(13)&Chr(10), "")


Rand





Similar Threads
Thread Thread Starter Forum Replies Last Post
Checking for a Carriage return darkhalf Classic ASP Databases 2 November 5th, 2007 06:15 AM
insert carriage return darkhalf Javascript 0 April 10th, 2007 02:42 PM
about carriage return... edu1980 XSLT 1 July 5th, 2006 04:11 AM
New Line/Carriage Return interrupt Javascript How-To 7 October 3rd, 2004 06:27 AM
HELP Inserting Carriage Return orangem Classic ASP Databases 8 July 5th, 2004 08:36 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.