Galera, I have this piece of XML and I need to remove the value (357122.40) that is between the < vMerc > xxxxxx < / vMerc > However, this value does not have a 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 on a table with many records. The following error appears:
Message 537, Level 16, State 3, Line 56 Invalid length parameter passed to the LEFT or SUBSTRING function.