I have several queries stored in an XML File. The entry giving me issues is:
<Xiphos>
SELECT
'AccountGrants',
cast (STUFF (SUBSTRING(b.PiiData,0,PATINDEX ('%</AccountNumber>%',b.PiiData ) ),1,24,'') as char(40) ) as Gen2accountNumber
,[GrantTypeId] as GrantType-- constant always 1
,[GrantAmount] as GrantedAmount
,[UsedAmount]
,[AwardedDate]
,[ExpirationDate]
FROM [Xiphos].[dbo].[AccountGrants]a
join Xiphos.dbo.Accounts b
on a.AccountId = b.AccountId
where b.FinancialInstitutionId =@InstitutionId
order by Gen2accountNumber,AwardedDate;
</Xiphos>
The 3rd line of the query that has “</AccountNumber>” in it is causing my project to not compile because it thinks this is a malformed XML statement (or missing the opening AccountNumber).
I can’t seem to figure out how to either reformat the query or modify my XML such that this doesn’t happen.
The PiiData column causing the problem looks like:
<PiiData><AccountNumber>150</AccountNumber>
The issue is with the
<and>characters in your query – they are treated as normal XML and you need to escape them – there are a couple of ways to do this.You can enclose the query in a
<![CDATA[]]>section:Alternatively, escape them by using their entity references –
<for<and>for>.