I have a column with a text data type , but its an xml field.When i try to execute a simple statement like
SELECT columnname,
CONVERT(xml,coloumnname)
FROM employee
This is running fine in QA since it has small amount to data. When i am running in the prod then the exception shoots up. Is there a way so that it can bypasses all the records which has an illegal xml character so that i can execute the code successfully. Using sql sever 2005/2008.
do anyone have a scrip for this?
Validate data on-the-fly is slow enough.
If you really do not want to use bad data, you should add column to table (e.g. “Is_Validated”).
Then run script which will check data and if it is converted to xml without exception, update column as 1 else 0.
When you run your statement, you should limit converting to xml where Is_Validated=1 only.
When you insert new row, check if is valid XML (using TRY/CATCH logic or CLR) and insert only valid rows.
When you logic be stable you can begin to validate your bad data.
Update:
Because of script from #2 should be run only one time, it can be simple TSQL:
Assuming you have primary key Id as int and xml column Columnname in Table Employee validated by MySchema