RE: Check to see if a table exists

From: Nigel Rivett (NigelRivett_at_discussions.microsoft.com)
Date: 06/24/04

  • Next message: j: "Headers and Footers from SQL"
    Date: Wed, 23 Jun 2004 23:21:01 -0700
    
    

    That will always execute the drop table
    if object_id('##Table') is null
            print 'True'
            else
            begin
            print 'False'
            Drop Table ##tmpTable
            end

    And think will only work if you are in tempdb - try

    if object_id('tempdb..##Table') is null
            print 'True'
    else
    begin
            print 'False'
            Drop Table ##tmpTable
    end

    "Kirk" wrote:

    > I am running Sql Server 7.0 and I am using a store procedure to drop a global temp table if it exists.
    >
    > Currently, it looks like this:
    >
    > if object_id('##Table') is null
    > print 'True'
    > else
    > print 'False'
    > Drop Table ##tmpTable
    >
    > It works fine through Query Analyzer, but when I try to execute this code through ASP code, I get the following error:
    >
    > Microsoft OLE DB Provider for SQL Server error '80040e09' With the statement printing out TRUE that the table doesn't exist. And if doesn't exist, it should continue on and create the table as instructed.
    >
    > Any ideas as to what I am doing wrong? Is there a better way to check as to whether or not a table exists? Any help would be appreciated.
    >
    > Thanks.
    >
    > Kirk
    >


  • Next message: j: "Headers and Footers from SQL"

    Relevant Pages

    • Re: A very strange behaviour
      ... > The result of the reports started to produce different results every time ... I execute the procedures, after hours of investigation I tries to shrink the ... When I shrink the tempdb again the same behavior repeated again. ...
      (microsoft.public.sqlserver.programming)
    • Re: Writing a GUID to a SQL table
      ... >> Hi Bob ... >> When I execute this code, ... >> Microsoft OLE DB Provider for SQL Server error '80040e14' ... >> Unclosed quotation mark before the character string ...
      (microsoft.public.inetserver.asp.db)
    • Re: Dynamic creation of ASP code
      ... > I am trying to generate ASP code on the fly as I want to be able to ... The Response.Write - Command only dumps the text you give him to the client. ... The Execute - Command actually executes the lines in the string and in this ...
      (microsoft.public.inetserver.asp.general)
    • Re: Web Applicaiton using Trusted Connections to SQL on different machine?
      ... > if I use ASP.NET code to make the connection, or if i just use ASP ... > My ASP code looks like this: ... > I get the Error on the .Execute ... Please reply to the newsgroup. ...
      (microsoft.public.sqlserver.security)
    • Re: Web Applicaiton using Trusted Connections to SQL on different machine?
      ... > if I use ASP.NET code to make the connection, or if i just use ASP ... > My ASP code looks like this: ... > I get the Error on the .Execute ... Please reply to the newsgroup. ...
      (microsoft.public.inetserver.iis.security)