1
People, I have this piece of an XML and I need to remove the value (357122.40) that is between the tags < vMerc>xxxxxx< /vMerc>. Only this value has no fixed size.
...<infCTeNorm><infCarga><vMerc>357122.40</vMerc><proPred>...
I tried doing this SQL:
SUBSTRING((CONVERT(VARCHAR(MAX), xml_conhecimento)), (PATINDEX('%<infCTeNorm><infCarga><vMerc>%', CONVERT(VARCHAR(MAX), xml_conhecimento)) + 30), (((PATINDEX('%</vMerc><proPred>%', CONVERT(VARCHAR(MAX), xml_conhecimento))) - (PATINDEX('%<infCTeNorm><infCarga><vMerc>%', CONVERT(VARCHAR(MAX), xml_conhecimento))))-30))
But it does not work in table with many records. Appearing the following error:
Message 537, Level 16, State 3, Line 56 Invalid length parameter passed to LEFT or SUBSTRING function.
2 questions: Could you provide the entire XML? Would you tell us in which XML your SQL fails?
– Dherik
Following is an xml link and I don’t know where it fails: https://www.webdanfe.com.br/danfe/exemplos/CTe_signed.html
– Adalberto