Add header row to query results

  • I need to add a row to my result set. So, the first row needs to identify my organization and have today's date. Then, the subsequent rows are the results of my query.

    The results of the sp get exported to a pipe delimited text file. Any thoughts?

    'Brockton Hospital', convert(varchar(8), getdate(), 112)

  • Add another column to signify row type or ordering and union all to join the two sets of data, i.e.

    SELECT 1 AS [RowType],

    'Brockton Hospital' AS [col1],

    CONVERT(varchar(8), GETDATE(), 112) AS [col2],

    '' AS [col3],

    '' AS [col4],

    '' AS [col5]

    UNION ALL

    SELECT 2 AS [RowType],

    col1,

    col2,

    col3,

    col4,

    col5

    FROM

    ORDER BY RowType ASC;

    Far away is close at hand in the images of elsewhere.
    Anon.

  • Great. Thanx.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply