Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using T-SQL to check whether a global temp table exists

Status
Not open for further replies.

VenkatSQL

Technical User
Nov 6, 2007
14
IN
Hi

How to check using T-SQL whether a global temp table exists or not...

thanks

s.v
 

It's crazy, all I typed into google was "sql to check if a global temp table exists" and the link posted above was the 2nd link returned.


Who would have known google was so helpful? Crazy....

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
Code:
[COLOR=blue]DECLARE[/color] @TableId [COLOR=blue]int[/color]
[COLOR=blue]SELECT[/color] @TableId = [COLOR=#FF00FF]OBJECT_ID[/color]([COLOR=red]'TempDB..##Test'[/color])
[COLOR=blue]SELECT[/color] @TableId

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
Microsoft MVP VFP
 
or even just:

select object_id('tempdb..##test')

--------------------
Procrastinate Now!
 
O! I missed the next part of the query:
Code:
[COLOR=blue]DECLARE[/color] @TableId [COLOR=blue]int[/color]
[COLOR=blue]SELECT[/color] @TableId = [COLOR=#FF00FF]OBJECT_ID[/color]([COLOR=red]'TempDB..##Test'[/color])
@TableId 
[COLOR=blue]IF[/color] @TableId [COLOR=blue]IS[/color] NULL
   [COLOR=green]-- Table does not exists
[/color][COLOR=blue]ELSE[/color]
   [COLOR=green]-- Table does exists[/color]

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
Microsoft MVP VFP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top