Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8047447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:06:03+00:00 2026-06-05T06:06:03+00:00

If I do Declare @t table(Email xml) Declare @email varchar(100) = ‘xxx&xx@monop.com’ Insert into

  • 0

If I do

Declare @t table(Email xml)
Declare @email varchar(100) = 'xxx&xx@monop.com'
Insert into @t  
select '<Emails> <Email>' + @email +'</Email></Emails>'
select * From @t

I will get expected error

Msg 9411, Level 16, State 1, Line 8
XML parsing: line 1, character 27, semicolon expected

One solution which I found almost everywhere(including SO) is to replace '&' with '&amp; and it works

Insert into @t  
select CAST('<Emails><Email>' + REPLACE(@email, '&', '&amp;') + '</Email></Emails>' AS XML)

Output

<Emails><Email>xxx&amp;xx@monop.com</Email></Emails>

However, I was trying with CData approach (just another way to approach the problem)

Declare @t table(Email xml)
Declare @email varchar(100) = 'xxx&xx@monop.com'
Insert into @t  
Select CAST('<![CDATA[Emails> <Email>' + @email + '</Email> </Emails]]>' AS XML)
select * From @t

When I got the below output

Emails&gt; &lt;Email&gt;xxx&amp;xx@monop.com&lt;/Email&gt; &lt;/Emails

What I am trying to achieve is to store the data as it is i.e. the desired output should be

<Emails><Email>xxx&xx@monop.com</Email></Emails>

Is it at all possible?

I know that the replace function will fail if any other special character that xml fails to understand will be passed as an input to it e.g. ‘<‘ i which case again we need to replace it…

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T06:06:06+00:00Added an answer on June 5, 2026 at 6:06 am

    Tags are PCDATA, not CDATA, so don’t put them in the CDATA section.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

DECLARE @table table(XYZ VARCHAR(8) , id int) INSERT INTO @table SELECT '4000', 1 UNION
Consider the following Transact sql. DECLARE @table TABLE(val VARCHAR(255) NULL) INSERT INTO @table (val)
Please look into the below query declare @t table(roleid int null,EmailAddress varchar(50) null) insert
Here's an example query: DECLARE @table table (loc varchar(10)) INSERT INTO @table VALUES ('134a'),
Here is my test SQL: declare @Table table (strField nvarchar(6), xmlField xml) insert into
Take the tsql query below: DECLARE @table TABLE(data VARCHAR(20)) INSERT INTO @table VALUES ('not
My table and data as following, declare @t1 table (myID varchar(200), chequeNo varchar(20)); insert
Consider the following sql server query , DECLARE @Table TABLE( Wages FLOAT ) INSERT
I have a table: declare @Table table (XmlPart xml, Cnt int) the XmlPart is
Take a standard broad search query...: DECLARE @sq Varchar(50) = 'Desperate' SELECT * FROM

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.