Dynamic Colum Name ???

  • Hi

    I'm trying to set a column name as the variable below
    Declare....
    Set @Month1s = cast(dateadd(month, -18, dateadd(day, 1 - day(getdate()), getdate())) as date)
    SET @test-2 = (RIGHT(CONVERT(VARCHAR(8), @Month1s, 3), 5))
    select....
    , case when
                 (Admission Date]<= @Month1e and [Discharge Date] >= @Month1s) or
    ([Discharge Date] is null and [Admission Date] <= @Month1e)
     then 1 else 0 end as Month1

    So what I would like is instead of the output saying Month1 as the column name , I would like the column name to be the value in @test-2 so in this case 12/15

    Possible??

    Thanks

    I

  • You'd have to use dynamic SQL.  This is really something you ought to be doing in your presentation layer instead, though.

    John

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

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