我是SQL Server中的XML新手。
我有这样的查询
declare @EstimateType char(1)
select top 1
ISNULL((case when @EstimateType='x' or @EstimateType='C' then
SUBSTRING((select ',' + ItemTitle from tb_Pricecatalogue WHERE PricecatalogueID IN(select PricecatalogueID from tb_DeliveryItem WHERE PriceCatalogueID = 0 )
FOR XML PATH('')),2,8000)
WHEN ISNULL((select top 1 et.ItemID FROM tb_DeliveryItem et WHERE et.DeliveryItemID = 252602 AND isdeleted = 0 ),0)>0 THEN
SUBSTRING((select ',' + ItemTitlevalue from tb_EstItemDescription WHERE EstimateItemID=
(246666) FOR XML PATH('')),2,8000) END),'') as ItemTitle
from tb_DeliveryItem d
where DeliveryItemID=252602 AND IsDeleted=0
将xml返回为
A4 PUR Bound Booklet - 4pp Cover + 116pp Text<br/><br/><br/>
如何将>
替换为>
,将<
替换为<
?
答案 0 :(得分:2)
看起来可以使用TYPE Directive
来实现我已修改查询以在TYPE
旁添加FOR XML PATH('')
指令的用法
DECLARE @EstimateType char(1)
SELECT TOP 1
ISNULL((
CASE WHEN @EstimateType='x' OR @EstimateType='C' THEN
SUBSTRING(( SELECT ',' + ItemTitle FROM tb_Pricecatalogue
WHERE PricecatalogueID IN ( SELECT PricecatalogueID
FROM tb_DeliveryItem
WHERE PriceCatalogueID = 0 )
FOR XML PATH(''), TYPE),2,8000)
WHEN ISNULL((SELECT TOP 1 et.ItemID
FROM tb_DeliveryItem et
WHERE et.DeliveryItemID = 252602
AND isdeleted = 0 ),0)>0 THEN
SUBSTRING(( SELECT ',' + ItemTitlevalue
FROM tb_EstItemDescription
WHERE EstimateItemID= (246666) FOR XML PATH(''), TYPE),2,8000) END),'') as ItemTitle
FROM tb_DeliveryItem d
WHERE DeliveryItemID=252602 AND IsDeleted=0
希望这有帮助!