• Why you need view and function?

    What's wrong with a single query

    select Id,ProductName,IsActive,

    CONVERT(XML,

    (SELECT TBL_Group.title, dbo.TBL_Group.id

    FROM TBL_Group INNER JOIN

    TBL_GroupProd ON TBL_Group.Id = TBL_GroupProd.GroupId

    WHERE TBL_GroupProd.ProdId = TBL_Product.Id FOR XML AUTO, ROOT('main'))) AS [Group]

    from dbo.TBL_Product

    where ProductName = 'P4'

    and exists (select null

    from TBL_GroupProd

    where TBL_GroupProd.ProdId = TBL_Product.Id

    and TBL_GroupProd.GroupId = 5)