Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends,

I need to eliminate XML Escape Characters (" ",' '< <> >& &)
after using "FOR XML PATH", With out using "REPLACE" Command I need to solve this.
Refer my sample data and pls give the solution.

SQL
-- Tables Creation
IF OBJECT_ID('TempDB..#Test') IS NOT NULL DROP TABLE #Test
CREATE TABLE #Test (ID INT, Name VARCHAR(30))
-- Sample Data
INSERT INTO #Test(ID, Name) VALUES(1,'Test'),(2,'&Test'), (3,'<test>')
-- Actual Data
SELECT ID, Name FROM #Test
-- Reguired Output
'Test,&Test,<test>'
SELECT STUFF((SELECT ','+Name AS [text()] FROM #Test FOR XML PATH('')),1,1,'')
-- Current Output
'Test,&Test,<test>'



Regards,
GVPrabu
Posted
Comments
Karthik Harve 18-Feb-13 4:03am    
What have you tried so far? Where you stuck?
gvprabu 18-Feb-13 4:32am    
Hi Karthik,

I am using REPLACE Command for solve this. But different solution Because I need to write 5 REPLACE Command for this.

Regards,
GVPrabu

Hi All,

At last I find the solution for this....
SQL
SELECT STUFF((SELECT ','+Name AS [text()] FROM #Test FOR XML PATH(''), TYPE).value('.', 'VARCHAR(MAX)'),1,1,'') AS 'NameList'


Check this :-)

Regards,
GVPrabu
 
Share this answer
 
v2
Comments
Karthik Harve 18-Feb-13 4:40am    
my 5+.!!
gvprabu 18-Feb-13 5:13am    
Hi Karthik,

Tnks
SQL
Select STUFF((SELECT ',' + cast(id as varchar) FROM x with (nolock)
 FOR XML PATH('')),1,1, '') as c
 
Share this answer
 
v2
Comments
gvprabu 18-Feb-13 4:31am    
HI Friend,

Check your Query,

I need to Remove All XML Escape Character after Join My Character Column.

As per your query it will convert INT Values to Character. Any how tnks


Regards,
GVPrabu

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900