Link to home
Start Free TrialLog in
Avatar of Ben Conner
Ben ConnerFlag for United States of America

asked on

Specifying a non-printable character constant in T-SQL

Hi,

I need to specify some non-printable characters as a search argument in a REPLACE function in T-SQL (MS SQL .  I thought this would be easy to find.  It isn't.

Is there a way to do this?

Thanks!

--Ben
Avatar of Raja Jegan R
Raja Jegan R
Flag of India image

>> I need to specify some non-printable characters as a search argument in a REPLACE function

Kindly explain more on this with examples to help you better..
Avatar of Ben Conner

ASKER

Hi,

One of the columns in a table has embedded cr/lf combinations  I need to replace those with blanks.

I thought the following would work:

select Replace(description,'0d0a'x,'  ') as desc
from products

where description is a varchar field.  I can't use the literal hex codes in this case as they get interpreted as a new line. :(  So...  I've tried x'0d0a', '0d0a'x, h'0d0a', '0d0a'h but can't come up with another way to write a hex specification for a 2 character search string. ??

Thanks!

--Ben
ASKER CERTIFIED SOLUTION
Avatar of Rajkumar Gs
Rajkumar Gs
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Try these also.

--Raj
SELECT dbo.regexReplace(yourfield, '[\x00-\x1f]', '', 1, 1 ) FROM yourtable;

Open in new window

Not sure. Just give a try

--Raj
DECLARE @regex integer;
SET @regex = dbo.regexObj( '[^a-z]', 1, 1 );
SELECT dbo.regexObjReplace( @regex, firstname, '' ) FROM account;

Open in new window


--Raj
DECLARE @regex integer;
SET @regex = dbo.regexObj( '[\x00-\x1f]', 1, 1 );
SELECT dbo.regexObjReplace( @regex, firstname, '' ) FROM account;

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Man, I love this group! :)  Thanks very much!

--Ben