CREATING DYNAMIC TEMPORARY TABLE

  • HI friends

    I have a requirement of creating temporary table dynamically inside a stored procedure . i have done like this

    DECLARE @SQL1 AS VARCHAR(MAX)

    SET @SQL1 =('Select '+@result +' into #Table21 from '+ @CompareTableName +' where ToEligibleVersion= '+ @Version2)

    EXEC(@SQL1)

    print @SQL1

    where all parameters are passed .

    when i check the print statement every thing is fine , but #table21 is not created .

    is there any problem with EXEC command .

    can any one let me to solve the problem

    Thanks

    nmsreddi

  • temp table created as part of dynamic query will not be visible outside the scope of the dynamic query. Try creating global temp table if that suits your purpose.

  • thanks for your reply , i have done the same , my problem solved by using global temp tables

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

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