April 6, 2016 at 1:41 pm
Say I have a value in a table = "brkXa"
I need a select statement that will replace the capital X with / so the result should look like this "brk/a". I do not want it to replace lower case x with /. So I don't want "nsx" to come back as "ns/".
I've tried these..
Select REPLACE(value, cast('X' as varbinary), '/') AS Test From table
I get brk/a but I also get ns/
Select REPLACE(value, UPPER('X'), '/') AS Test From table
I get brk/a but I also get ns/
Any help is greatly appreciated.
April 6, 2016 at 1:48 pm
Try this,
REPLACE(value COLLATE Latin1_General_Bin, 'X', '/')
April 6, 2016 at 8:30 pm
You could also do this:
REPLACE(value, char(88), '/')
-- Itzik Ben-Gan 2001
April 7, 2016 at 7:39 am
Alan.B (4/6/2016)
You could also do this:
REPLACE(value, char(88), '/')
This did not work. Gave me the same results.
April 7, 2016 at 7:40 am
Thanks ZZartin, that worked perfectly.
April 7, 2016 at 7:44 am
Alan.B (4/6/2016)
You could also do this:
REPLACE(value, char(88), '/')
The replacement depends on the collation, and the default collation is case insensitive. Using the CHAR() function, does not change the default collation, so it does not change the behavior of the replace.
Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
April 8, 2016 at 9:33 am
drew.allen (4/7/2016)
Alan.B (4/6/2016)
You could also do this:
REPLACE(value, char(88), '/')
The replacement depends on the collation, and the default collation is case insensitive. Using the CHAR() function, does not change the default collation, so it does not change the behavior of the replace.
Drew
Yep. I was not able to test my code when I posted it.
-- Itzik Ben-Gan 2001
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply