Not defined temp table in a function

  • Hello,

    I want to create a function with one variable what is a table name. this function has to give me back all the records from the table witch name is given in the variable. The problem is that i've more than 100 table with diffent numbers of collumns and different collumn-names so I cann't declare the temporary table

    The next code is working fine but when I try to put this code in a function the next error occurs

    "Cannot access temporary tables from within function"

    The code i wrote is

    EXEC ('SELECT * INTO ##TEMPTABLE FROM [' + @TABL + '] ')

    select [ID] from ##TEMPTABLE

    drop table ##TEMPTABLE

    My question, How can I get this code in a function?

  • You cannot use this syntax within a function.

    I don't think you can get a table variable to work here either as it requires you define the table structure.

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

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