 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Jon Jacobs Guest
|
Posted: Mon Aug 15, 2005 9:43 pm Post subject: Detect temp table |
|
|
D6, TADOQuery, MS SQL Server
I need to create and destroy temp tables (eg: #MyTableName).
Sometimes there is the possibility a temp table may be left around because of an exception elsewhare.
So I have to drop the table before I create it, just to be sure. Of course this creates an exception if the table does not
exist, so I have to surround the drop query with try..excpet, with an empty except clause.
All is smooth for the end user, but when debugging, the frequent exception breaks are quite annoying. I dare not turn off
the break on exception because I am usually looking for excpetions when debugging.
Is there a way to detect if a given named temp table exists? Then I could drop it only if it exists.
Thanks,
Jon
|
|
| Back to top |
|
 |
Bryan Valencia Guest
|
Posted: Mon Aug 15, 2005 10:02 pm Post subject: Re: Detect temp table |
|
|
Look for GetTableNames in the TADOConnection Help
"Jon Jacobs" <JonJacobsAtcomcast.net> wrote
| Quote: | D6, TADOQuery, MS SQL Server
I need to create and destroy temp tables (eg: #MyTableName).
Sometimes there is the possibility a temp table may be left around because
of an exception elsewhare.
So I have to drop the table before I create it, just to be sure. Of course
this creates an exception if the table does not
exist, so I have to surround the drop query with try..excpet, with an
empty except clause.
All is smooth for the end user, but when debugging, the frequent exception
breaks are quite annoying. I dare not turn off
the break on exception because I am usually looking for excpetions when
debugging.
Is there a way to detect if a given named temp table exists? Then I could
drop it only if it exists.
Thanks,
Jon
|
|
|
| Back to top |
|
 |
Jon Jacobs Guest
|
Posted: Sat Aug 20, 2005 2:40 am Post subject: Re: Detect temp table |
|
|
| Quote: | Look for GetTableNames in the TADOConnection Help
Thank you. Unfortunately, the TADOConnection only has information about the connection to a particular database. Temporarty |
tables are in a different database, tempdb. The connection knows nothing about it. Thanks for trying.
Jon
|
|
| Back to top |
|
 |
Dennis Passmore Guest
|
Posted: Sun Aug 21, 2005 2:05 pm Post subject: Re: Detect temp table |
|
|
this is how I handle it,
just execute using the TADOConnection.execute( sqlcmd ) function and disregard the
results.
if object_id('tempdb..#tmptable') is not null -- may already exist because of
drop table #tmptable -- recursive stored procedure call below
|
|
| Back to top |
|
 |
Jon Jacobs Guest
|
Posted: Sun Aug 21, 2005 8:02 pm Post subject: Re: Detect temp table |
|
|
| Quote: | just execute using the TADOConnection.execute( sqlcmd ) function and disregard the
results.
if object_id('tempdb..#tmptable') is not null -- may already exist because of
drop table #tmptable -- recursive stored procedure call below
Thanks. Addressing tempdb..#etc is the key. I appreciate it. |
Jon
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|