How to escape a string embedded in XML to be used in a SQL Server 2008 XML field?

ghorab

New Member
I have the following SQL insert statement.\[code\]insert into [dbo].[Lookup] (XMLField) select '<root>' + '<SQL>' + SQLQueryToEscape + '</SQL>' + '</root>' as CustomData from dbo.CustomView \[/code\]My dilemma is that the SQLQueryToEscape has characters in it that aren't XML safe. I need to escape the string. What is the best way to do this in tSQL?
 
Back
Top