• I honestly believe that you are trying to do something wrong, but...

    Here we go:

    ;WITH cte_ref

    AS

    (

    SELECT R.*, ROW_NUMBER() OVER (PARTITION BY F_data_id ORDER BY F_ref_id) N

    FROM [T_Lookup_Ref] R

    )

    , cte_set

    AS

    (

    SELECT S.N

    ,M.F_data_id

    ,M.F_looup_desc

    FROM T_Master_lookup M

    CROSS JOIN (SELECT DISTINCT N FROM cte_ref) S(N)

    )

    SELECT R.F_ref_id

    ,R.F_data_id

    ,R.F_ref_desc

    ,M.F_looup_desc

    FROM cte_set M

    LEFT JOIN cte_ref R

    ON R.N = M.N

    AND R.F_data_id = M.F_data_id

    ORDER BY M.N, M.F_looup_desc, R.[F_ref_id]

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]