Drop #Temp Table

  • Ok, I had this code before and now I can't find it, how do I get the code do drop a temp table at the start of my query.

    Right now I am saying

    Drop table #Temp

    Select top 10 * from tableX into #TEMP

    The first time that I run this I get an error statement, I need to put something into an SP and I have a lot of temp tables, I can't remember the code.

  • Richard,

    This script will drop temp table if it exist.

    /* drop the temporary table if already exists */

    If Object_Id(‘tempdb..#temp') is Not Null

    Drop table #temp

    /* create temporary table */

    Create TABLE #temp (

    a char(2),

    b char(2),

    c char(2)

    )

    Kindest Regards,

    Sameer Raval [Sql Server DBA]
    Geico Insurance
    RavalSameer@hotmail.com

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

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