任何機構可以幫助我,爲什麼我會收到這個錯誤「附近有語法錯誤FOR XML ROW,不正確的語法,
在這個標量函數
ALTER
FUNCTION [DBO].[GetBaseTypeProductsAsXml](
@CountryID INT ,
@BaseTypeID INT = -1) RETURNS XML
AS
BEGIN
DECLARE
@Result XML;
SELECT @Result =
(SELECT TOP 10 BP.Id AS BaseProductId,
BP.Name AS ProductName,
Product.StartingPrice AS Price,
HeaderImage.Path AS ImagePath
FROM [BaseProducts] BP
INNER JOIN [Products] Product
ON (BP.Id = Product.BaseProductId
AND Product.CountryId = @CountryID) OUTER APPLY
(SELECT TOP 1 HeaderImage.[Path]
FROM [DBO].Images AS [HeaderImage]
INNER JOIN [DBO].ProductsImages AS ProductsImages
ON HeaderImage.Id = ProductsImages.ImageId
WHERE ProductsImages.BaseProductId = BP.Id
ORDER BY [ProductsImages].[ORDER]
) AS HeaderImage
WHERE BP.TypeId = @BaseTypeID FOR XML ROW 'Error is here'
)
RETURN @Result;
END
感謝
哪個數據庫?它看起來像SQL Server(2008,2012?) – tgolisch
是的,它是SQL Server 2012 – user123456