Dynamic Column Names in the Result Set

  • Hi

    I am trying to assign a column name based on input parameter, is this at all possible? I.e.

    declare @monthName varchar(10)

    set @monthName = 'January'

    select datepart(day, timestamp) as 'Day', count(*) as 'Books sold in ' + @monthName

    from sales

    I want the second column's name to be [Books sold in January]. I know that I could do this:

    declare @monthName varchar(10)

    set @monthName = 'January'

    declare @query varchar(8000)

    select @query =

    ' select datepart(day, timestamp) as [Day], count(*) as [Books sold in ' + @monthName + ']

    from sales'

    exec (@query)

    Reason for trying to do the first method is that I need to define the column names in the query - when displayed, I cannot do any manipulation, WYSIWYG system.

    Thanks!

    Cobus

  • no, i don't think that is possible you will need to use the second method


    Everything you can imagine is real.

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

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