• Not only is it important to name columns (as opposed to using '*') - it is important to name them and return them in the same order!

    Nothing in the 'MAV' query guarantees the order of column names returned. Use FOR XML PATH with an explicit ORDER BY clause instead (it's faster and entirely documented):

    SELECT STUFF(

    (

    SELECT N',' + sc.name

    FROM sys.columns sc

    WHERE sc.[object_id] = OBJECT_ID(N'dbo.Widget', N'U')

    ORDER BY

    sc.column_id ASC

    FOR XML PATH(''), TYPE

    ).value(N'.[1]', 'NVARCHAR(MAX)'), 1, 1, '');