April 19, 2017 at 9:55 am
Hi I need to replace these values as blank space from a string
Hello all! &
#160; How Are you ?:
AS
Hello all! How Are you ?
Thanks,
April 19, 2017 at 10:00 am
What have you tried?
You could use PATINDEX to search for '&#%;' and do the replace from there. You may need a string splitter - I'm not sure.
John
April 19, 2017 at 10:01 am
You should be able to do this one yourself, considering how long you've been here 🙂
Thom~
Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
Larnu.uk
April 19, 2017 at 10:17 am
PSB - Wednesday, April 19, 2017 9:55 AMHi I need to replace these values as blank space from a stringHello all! &
#160; How Are you ?:AS
Hello all! How Are you ?Thanks,
This should be "Hello all! How Are you :" unless you provide further logic.
😎
April 19, 2017 at 10:25 am
right
April 19, 2017 at 11:26 am
Would this work for you?SELECT *, CAST(CAST(String AS XML) AS VARCHAR(MAX))
FROM (VALUES('Hello all! How Are you ?:'))x(String)
April 19, 2017 at 11:38 am
This might be a slower method, but it will do exactly what you asked in your first post.
SELECT *,
( SELECT CASE WHEN s.Item LIKE '#[0-9]%'
THEN STUFF( s.Item, 1, CHARINDEX(';', s.Item), ' ')
ELSE s.Item END
FROM dbo.DelimitedSplit8K( x.String, '&') s
FOR XML PATH(''), TYPE).value('./text()[1]', 'varchar(max)')
FROM (VALUES('Hello all! How Are you ?:'))x(String)
The splitter function is explained in here: http://www.sqlservercentral.com/articles/Tally+Table/72993/
April 19, 2017 at 1:05 pm
Thom A - Wednesday, April 19, 2017 12:32 PMI might be being daft, but is this not as simple as:REPLACE(REPLACE('Hello all! How Are you ?:', ' ',''),':','')
I'm sure those are not the only two codes that need to be replaced.
https://www.w3.org/TR/html4/charset.html#h-5.3
April 19, 2017 at 2:22 pm
Luis Cazares - Wednesday, April 19, 2017 1:05 PMThom A - Wednesday, April 19, 2017 12:32 PMI might be being daft, but is this not as simple as:REPLACE(REPLACE('Hello all! How Are you ?:', ' ',''),':','')
I'm sure those are not the only two codes that need to be replaced.
https://www.w3.org/TR/html4/charset.html#h-5.3
And, there''s the rather slow performance for the REPLACE function over large numbers of records to worry about as well.
Steve (aka sgmunson) 🙂 🙂 🙂
Rent Servers for Income (picks and shovels strategy)
April 19, 2017 at 6:26 pm
sgmunson - Wednesday, April 19, 2017 2:22 PMLuis Cazares - Wednesday, April 19, 2017 1:05 PMThom A - Wednesday, April 19, 2017 12:32 PMI might be being daft, but is this not as simple as:REPLACE(REPLACE('Hello all! How Are you ?:', ' ',''),':','')
I'm sure those are not the only two codes that need to be replaced.
https://www.w3.org/TR/html4/charset.html#h-5.3And, there''s the rather slow performance for the REPLACE function over large numbers of records to worry about as well.
That's pretty much a myth unless you've used a collation that's a bit heavy handed. Nested replaces actually rock for performance when done correctly.
Do you have a link for the slow performance claim? I'd like to have a look and see what they've done.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply