Bobby X
asked on
URGENT: Need help with parsing TEXT data using PADINDEX...
Hi,
The padindex doesn't seem to be able to find "<var name="SERIALNUMBER"><strin g>" due to the double quots (") around SERIALNUMBER. How do I esape it so that it works? See sql below:
select substring(t1, 0, patindex('%</string%', t1)) as t11
from
(select
case when patindex('%<var name=''SERIALNUMBER''><str ing>%', product) > 0 then
substring(product, patindex('%<var name=''SERIALNUMBER''><str ing>%', product)+33, 99)
when patindex('%<var name="SERIALNUMBER"><strin g>%', product) > 0 then
substring(product, patindex('%<var name=''SERIALNUMBER''><str ing>%', product)+33, 99)
end as t1
from temp_001
) as x
I have "product" data that have both "<var name='SERIALNUMBER'><strin g>" and "<var name=''SERIALNUMBER''><str ing>"
This is in reference to: https://www.experts-exchange.com/questions/25337139/URGENT-Need-help-on-parsing-TEXT-data.html
I'm using SQL Server 2005.
Many thanks.
The padindex doesn't seem to be able to find "<var name="SERIALNUMBER"><strin
select substring(t1, 0, patindex('%</string%', t1)) as t11
from
(select
case when patindex('%<var name=''SERIALNUMBER''><str
substring(product, patindex('%<var name=''SERIALNUMBER''><str
when patindex('%<var name="SERIALNUMBER"><strin
substring(product, patindex('%<var name=''SERIALNUMBER''><str
end as t1
from temp_001
) as x
I have "product" data that have both "<var name='SERIALNUMBER'><strin
This is in reference to: https://www.experts-exchange.com/questions/25337139/URGENT-Need-help-on-parsing-TEXT-data.html
I'm using SQL Server 2005.
Many thanks.
can you please post a sample data and what you want to see
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi HainKurt,
You can find sample data in the original post: This is in reference to: https://www.experts-exchange.com/questions/25337139/URGENT-Need-help-on-parsing-TEXT-data.html
Thanks.
You can find sample data in the original post: This is in reference to: https://www.experts-exchange.com/questions/25337139/URGENT-Need-help-on-parsing-TEXT-data.html
Thanks.
ASKER
Hi Rimvis,
I'll give it a try tomorrow when I return to work tomorrow morning.
Thanks.
I'll give it a try tomorrow when I return to work tomorrow morning.
Thanks.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
HainKurt,
In your "declare @product varchar(max) = '<wddxPacket version=''1.0''><header/>< data><stru ct>...", try to replace the 2 single quotes (' ') around SERIALNUMBER (see below) with double quotes (") in your sql server management studio query analyzer so that it looks like this <var name="SERIALNUMBER"><strin g>34151461 646</strin g></var>:
<var name=' 'SERIALNUMBER' '><string>34151461646</str ing></var> --try replacing the 2 single quotes (' ') with double quotes (")
Then run it and see if it works. In other words, my original sample data may have double quotes (") instead of 2 single quotes (' ') around SERIALNUMBER.
Many thanks.
In your "declare @product varchar(max) = '<wddxPacket version=''1.0''><header/><
<var name=' 'SERIALNUMBER' '><string>34151461646</str
Then run it and see if it works. In other words, my original sample data may have double quotes (") instead of 2 single quotes (' ') around SERIALNUMBER.
Many thanks.
ASKER
Ok, I finally found out what the problem was. The solution was to replace the double qoute (") with 4 single quotes ('''') so that it looks like this:
select substring(t1, 0, patindex('%</string%', t1)) as t11
from
(select
case when patindex('%<var name=''SERIALNUMBER''><str ing>%', product) > 0 then
substring(product, patindex('%<var name=''SERIALNUMBER''><str ing>%', product)+33, 99)
when patindex('%<var name=''''SERIALNUMBER''''> <string>%' , product) > 0 then
substring(product, patindex('%<var name=''''SERIALNUMBER''''> <string>%' , product)+55, 99)
end as t1
from temp_001
) as x
Many thanks to all of you.
select substring(t1, 0, patindex('%</string%', t1)) as t11
from
(select
case when patindex('%<var name=''SERIALNUMBER''><str
substring(product, patindex('%<var name=''SERIALNUMBER''><str
when patindex('%<var name=''''SERIALNUMBER''''>
substring(product, patindex('%<var name=''''SERIALNUMBER''''>
end as t1
from temp_001
) as x
Many thanks to all of you.