dynmic temp table help

  • select @col = COALESCE(@col + ',','')+ QUOTENAME(Datename(month,work_date ))

    from form_Details WHERE Work_Date between '2012-01-01' and '2012-02-28'

    GROUP BY Datename(month,work_date)

    ORDER BY Datename(month,work_date) DESC

    print @col

    CREATE TABLE #cmd_holiday (@col float ) --> i want like this dynamic (January float ,February Float)

    INSERT #cmd_holiday

    execute [GetHolidaySumNewHours] '2012-01-01','2012-02-28'

    select * from #cmd_holiday

    any way to solve this please !

  • You may have to use Global Temp Tables or persisted tables to do that.. If you need your column names to be dynamically included in the CREATE Table clause, you will have to use dynamic SQL.

    As a side bar, what is the output of [GetHolidaySumNewHours] ? What column names does this SP output?

  • First of all

    CREATE TABLE #cmd_holiday (@col float ) --> i want like this dynamic (January float ,February Float)

    -- should be

    --CREATE TABLE #cmd_holiday (col float )

    Second we have no idea what this does

    INSERT #cmd_holiday

    execute [GetHolidaySumNewHours] '2012-01-01','2012-02-28'

    select * from #cmd_holiday

    Can you post some sample data returned by the SP GetHolidaySumNewHours

    To do this quickly and easily please read the article which is in the first link in my signature block. With that information some one may be able to assist you with a tested solution.

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

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

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