大家好我尝试使用下面的查询写入文件。 这是一个关于30声明的动态调用。 第一次调用是好的我写了一行(结果变成了变量,这一次写入文件)。从第二轮开始我得到了这个错误: “父标记ID 1不在开放标记中。FOR XML EXPLICIT要求首先打开父标记。检查结果集的顺序”。
我不理解,因为我可以解决。
SELECT DISTINCT
1 as Tag,
NULL as Parent,
NULL AS [Products!1], -- empty root element
NULL AS [Product!2!ExternalId!element],
NULL AS [Product!2!Name!element],
NULL AS [Product!2!Description!element],
NULL AS [Product!2!BrandExternalId!element],
NULL AS [Product!2!CategoryExternalId!element],
NULL AS [Product!2!ProductPageUrl!cdata],
NULL AS [Product!2!ImageUrl!cdata],
NULL AS [Product!2!],
NULL AS [Product!2!]
UNION ALL
SELECT
2 AS Tag,
1 AS Parent,
NULL,
ExternalId,
[Name],
[Description],
REPLACE(BrandExternalId,'/','_') as BrandExternalId,
IDnodo as CategoryExternalId,
ProductPageUrl,
ImageUrl,
(
SELECT ManufacturerPartNumber
FOR XML PATH('ManufacturerPartNumbers'),TYPE
),
(SELECT b.EAN
FROM Cestino.acap.Bazaar_Servizio_01 b
WHERE (ff.ExternalId = b.codart)
AND PATINDEX('%[^0-9]%', b.EAN) = 0
AND CHARINDEX('.', b.EAN) = 0
AND LEN(b.EAN) = 13
AND isNumeric(b.EAN) = 1
FOR XML PATH(''), ROOT('EANs'), TYPE)
FROM Cestino.acap.Bazaar_Servizio_00 ff with (nolock)
--WHERE ExternalId = 100212694
ORDER BY 3, Parent
OFFSET ((2 - 1) * 10000) ROWS
FETCH NEXT 1000 ROWS ONLY
FOR XML EXPLICIT
答案 0 :(得分:0)
尝试一下:
SELECT DISTINCT
1 as Tag,
NULL as Parent,
NULL AS [Products!1], -- empty root element
NULL AS [Product!2!ExternalId!element],
NULL AS [Product!2!Name!element],
NULL AS [Product!2!Description!element],
NULL AS [Product!2!BrandExternalId!element],
NULL AS [Product!2!CategoryExternalId!element],
NULL AS [Product!2!ProductPageUrl!cdata],
NULL AS [Product!2!ImageUrl!cdata],
NULL AS [Product!2!],
NULL AS [Product!2!]
UNION ALL
SELECT
2 AS Tag,
1 AS Parent,
NULL,
ExternalId,
[Name],
[Description],
REPLACE(BrandExternalId,'/','_') as BrandExternalId,
IDnodo as CategoryExternalId,
ProductPageUrl,
ImageUrl,
(
SELECT ManufacturerPartNumber
FOR XML PATH('ManufacturerPartNumbers'),TYPE
),
(SELECT b.EAN
FROM Cestino.acap.Bazaar_Servizio_01 b
WHERE (ff.ExternalId = b.codart)
AND PATINDEX('%[^0-9]%', b.EAN) = 0
AND CHARINDEX('.', b.EAN) = 0
AND LEN(b.EAN) = 13
AND isNumeric(b.EAN) = 1
FOR XML PATH(''), ROOT('EANs'), TYPE)
FROM Cestino.acap.Bazaar_Servizio_00 ff with (nolock)
--WHERE ExternalId = 100212694
ORDER BY 3, Parent
OFFSET ((2 - 1) * 10000) ROWS
FETCH NEXT 1000 ROWS ONLY
Order by Tag
FOR XML EXPLICIT