sql - Temporary table will not drop -
sql - Temporary table will not drop -
this question has reply here:
drop temp table if exists 2 answersthe conditional drop table line in code below doesn't seem work. executes without error, next line errors saying object id exists - it's not dropping table.
any ideas?
i'm connecting ms sql server 2005 database through ole db (sqloledb provider) using ado.
class="lang-vb prettyprint-override">'create temporary table on sql server , insert info end part adocma set .activeconnection = mobjcon .commandtype = adcmdtext .commandtext = "if object_id('" & temptable & "') not null drop table " & temptable .execute .commandtext = "create table " & temptable & " (item varchar(255),descrip1 char(255),descrip2 char(255), lev int, seq varchar(255), flag1 tinyint, primarykey int identity(1,1) primary key,qty_per float)" .execute .commandtext = "insert " & temptable & " (item,descrip1,descrip2,lev,seq,flag1,qty_per) select item_no,item_desc_1,item_desc_2,1,1,'1',1 " & cstrmactitem & " item_no ='" & stritem & "' " .execute end
fwiw temptable name created @ runtime using format #[wsid]temp[now]
, truncated 116 characters, example:temptable=#lokspec1temp141031155408
also, i've tried escaping table name using single quotes or double quotes same result (it doesn't drop). found square brackets raise syntax error.
sql creates tables prefaced pound sign in whole other place current working database. if want interrogate schema info of temp table, need explicitly reference other database. might easier see if tweaked code this
.commandtext = "if object_id('tempdb.." & temptable & "') not null drop table " & temptable
sql sql-server ado temp-tables drop-table
Comments
Post a Comment