简体   繁体   中英

Replace() in SQL isn't working with "

I'm receiving a JSON string into a database which I'm trying to convert into a comma delimited list. This is my current state:

在此处输入图片说明

My SQL currently looks like:

BEGIN TRANSACTION

SELECT  Id, 
        PriorityGroups ,
        REPLACE(
            REPLACE(
                REPLACE(PriorityGroups, '["', ''), 
                    '"]', ''), 
                    '"."', ', ') AS 'Updated to comma delimited'
FROM    dbo.CA
WHERE   Id= 51

ROLLBACK TRANSACTION

For whatever reason when I try to replace

"."

With a comma and a space it's not making any changes to the output. I've tried escaping the double quotes but I'm being told it's invalid syntax and I'm not too sure what else to try!

Its not "." to be replaced in string. The characters to be replaced are ","

SELECT  Id, 
        PriorityGroups ,
        REPLACE(
            REPLACE(
                REPLACE(PriorityGroups, '["', ''), 
                    '"]', ''), 
                    '","', ', ') AS 'Updated to comma delimited'
FROM    dbo.CA
WHERE   Id= 51

A valid JSON string is comma delimited and not delimited by period . character

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM