• This should do the trick, however, I can't assure you that because I have nothing to test on.

    Be aware that you can't use ORDER BY in a TVF because it would be useless.

    If you're not receiving any parameters, you could as well use a view instead of a function (I'm not sure if there would be any difference on performance or something else).

    CREATE FUNCTION [dbo].[Cat1AndCat2Sector_cat2]()

    RETURNS TABLE

    AS

    RETURN

    (

    SELECT STUFF((SELECT ',' + CAST( Code AS varchar( 15))

    FROM Knowledge_domains

    WHERE DOMAIN_TYPE ='MASTER'

    FOR XML PATH('')), 1, 1, '') as Code,

    'All' as Name

    UNION ALL

    SELECT CAST( Code AS varchar(8000)),

    Name

    FROM Knowledge_domains

    WHERE DOMAIN_TYPE ='MASTER'

    )

    For explanation on the concatenation, read the following article: http://www.sqlservercentral.com/articles/comma+separated+list/71700/

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2