Question

My string is as below :

<SL1> Locationdetails are in the table .<RXCH><cF7712>Location1<cF4712>
        <RXCS1>H1<RXCS2>H2<RXCS3>H3
        <RXC11>C11<RXC12>C12
        <RXC13>C13<RXC21>C21
        <RXC22>C22<RXC23>C23
        <RXC31>C31<RXC32>C32
        <RXC33>C33<RXC41>C41
        <RXC42>C42<RXC43>C43
        <RXC51>C51<RXC52>C52
        <RXC53>C53
        <RXCH><cF7712>Location1<cF4712>
        <RXCS1>H1<RXCS2>H2<RXCS3>H3
        <RXC11>C11<RXC12>C12
        <RXC13>C13<RXC21>C21
        <RXC22>C22<RXC23>C23
        <RXC31>C31<RXC32>C32
        <RXC33>C33<RXC41>C41
        <RXC42>C42<RXC43>C43
        <RXC51>C51<RXC52>C52
        <RXC53>C53. Services for primary health care'

I would like to split the above string and the output as below:

OUTPUT should be:

'Location1 H1 H2 H3 C11 C12 C13 C21 C22 C23 C31 C32 C33 C41 C42 C43 C51 C52 C53 Location1 H1 H2 H3 C11 C12 C13 C21 C22 C23 C31 C32 C33 C41 C42 C43 C51 C52 C53'
Était-ce utile?

La solution

-- Get text between points
set @str = stuff (@str, 1, charindex ('.', @str), '')
set @str = left (@str, charindex ('.', @str) - 1)
-- Get rid of spaces, tabs and line ends
set @str = replace (replace (replace (replace (@str, ' ', ''), char(9), ''), char(10), ''), char(13), '')
-- Output
select ltrim (cast(replace (@str, '>', '/> ') as xml).value('.', 'varchar(max)'))
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top