user123456
user123456

Reputation: 2659

Incorrect syntax near FOR XML ROW,

Can any body help me why am I getting this error "Incorrect syntax near FOR XML ROW,

in this Scalar Function

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

Thanks

Upvotes: 0

Views: 610

Answers (1)

tgolisch
tgolisch

Reputation: 6734

If this is SQL Server, there is no FOR XML Row. Perhapse you meant XML Raw. Otherwise, to represent each row in a result set, you can simply say FOR XML Path.

Upvotes: 2

Related Questions