How do I check if #tempTable exists?

Is there a way in T-SQL  to check to see if a #tempTable exists?  I want to write a proc the uses a temp table, but I first need to see if the table already exists.  if it does I want to drop it, otherwise skip

Remember that temporary tables are specific to a user, so #test does not exist in tempdb.  It will be named something like #test_____________________. 
So select object_id('tempdb..#test') will fail.  You will need to use something like:
SELECT [name] FROM tempdb.dbo.sysobjects WHERE xtype = 'U' and [name] like '#test%'
In SQL 2005 you should also be using the new schemas which are much easier to understand:
SELECT [name] FROM tempdb.sys.tables WHERE [name] like '#test%'
And in SQL2005 there's an easier way without having to resort to tempdb at all.  Use the Try..Catch block.  In my example, I've put a message in the Catch block, but if you leave it blank the statement will not fail if the table doesn't exist.  It would if you tried a plain DROP TABLE #test on a non-existent table.
BEGIN TRY
  DROP TABLE #test
END TRY
BEGIN CATCH
  PRINT 'does not exist'
END CATCH

Similar Messages

  • What is DIR_CT_RUN?, how can I check it is exist?

    I'm trying to patching my Netweaver2004s system. Document tells me to check DIR_CT_RUN existance.
    My SAPSID is BXD, how can I check DIR_CT_RUN existance?
    Thanks.

    hi ,
    check in rz11.
    dir_ct_run points to the run directory i.e /usr/sap/<sid>/SYS/exe/run.
    regards,
    yatindra
    Message was edited by:
            yatindra mehta

  • Check booking whether exist

    hi all, how can i check the booking exist or not before add booking??thanks
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
               Connection con = DriverManager.getConnection("jdbc:odbc:booking");
               PreparedStatement pstat = con.prepareStatement("insert into booking values(?,?,?,?,?,?,?,?)");
                   memberno = tf1.getText();
                   pstat.setString(1,memberno);
                   facilityno= ch1.getSelectedItem();
                   pstat.setString(2,facilityno);
                   date = ch2.getSelectedItem();
                   pstat.setString(3,date);
                   time = ch3.getSelectedItem();
                   pstat.setString(4,time);
                   int no1 = (int) (Math.random()*10000);
                String referenceno = String.valueOf(no1);
                tf2.setText(referenceno);
                  pstat.setString(5,referenceno);
                pstat.setString(6,"accepted");
                   collectiondate = date;
                tf3.setText(collectiondate);
                pstat.setString(7,collectiondate);
                   collectiontime = time;
                   tf4.setText(collectiontime);
                pstat.setString(8,collectiontime);
                   pstat.executeUpdate();
                   tf1.setText("");
               pstat.close();
               con.close();
    [\code]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  

    2 errors,
    method getSelectedItem(int), location:interface java.sql.ResultSet
    String date1 = String.valueOf(rs.getSelectedItem(1));
    method getSelectedItem(int), location:interface java.sql.ResultSet
    String time1 = String.valueOf(rs.getSelectedItem(2));
    thanks
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
               Connection con = DriverManager.getConnection("jdbc:odbc:booking");
            PreparedStatement ps = con.prepareStatement("select date, time from booking where date = ? and time = ?");
               ps.setString(1,ch2.getSelectedItem());
               ps.setString(2,ch3.getSelectedItem());       
            ResultSet rs = ps.executeQuery();
            while (rs.next()){
              String date1 = String.valueOf(rs.getSelectedItem(1));
              String time1 = String.valueOf(rs.getSelectedItem(2));
                  if (date.equals(date1) && time.equals(time1)){
                   JOptionPane.showMessageDialog(this,"booked.");
                   booking bk = new booking();     
                   bk.setVisible(true);
             rs.close();
             ps.close();
    [\code]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How can i check if a procedure exists in a certain database version

    So today i became really frustrated after noticing that the Oracle SQL version on some computer I needed to work on was 10.1. The problem with that was that I needed a procedure called "xmlserialize". I browsed the documentation for it, but I didn't see anything like "since 11.0" or something similar.
    So.. how can I see what is the first Oracle SQL version that supported some procedure?
    For example, when I check a class definition for Java, I consult the javadoc :
    http://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html
    and there there's a field called "Since". For BigInteger ( it's just an example ), it says "Since: JDK1.1", so I know that if I'm using a JDK version earlier that 1.1, I won't have that class.
    Is there some similar information for Oracle procedures/ functions/ features/ etc?

    >
    Let me be more explicit. I've searched for xmlserialize function.
    The only place on the website that holds information regarding this function is this page:
    >
    To paraphrase sybrand - that's utter nonsense. I have never found only one reference to anything on the web.
    Your question subject is
    >
    how can i check if a procedure exists in a certain database version
    >
    And since you said you were using 10.1 I searched for
    >
    oracle 10.1 xmlserialize
    >
    And the very first link on the search results is
    >
    What's New In Oracle XML DB?
    http://docs.oracle.com/cd/B19306_01/appdev.102/b14259/whatsnew.htm
    >
    That link is for the XML Db Dev Guide for 10g Release 2
    Would you like to guess what you find if you search for xmlserialize?
    Right on the very first page is this
    >
    Oracle Database 10g Release 2 (10.2) New Features in Oracle XML DB
    SQL/XML Standard Compliance (SQL:2005 Standard Part 14)
    Support for the developing SQL/XML standard has been extended. The following SQL functions have been added: XMLPI, XMLComment, XMLRoot, XMLSerialize, XMLCDATA, and XMLParse. Escaping of identifiers has also been updated, in accordance with a change to the SQL/XML standard. See "Generating XML Using SQL Functions".
    >
    Did you notice the second sentence? I removed the clutter to make it easier to see.
    >
    The following SQL functions have been added: . . .XMLSerialize. . .
    >
    Fnding information can't get any easier than that.

  • How do I check if section and subdivision exist inside object's xml?

    My function is working but not as I expect it to. The problem is that when Section and Subvision are not found in the object aobjXmlGetStatuteRequestNode xml, I get an error NullReference Exception was unhandled by user code. Object reference not set
    to an instance of an object. 
    For that reason, because the two elements are optional, I would like to check if they exist before adding their value into the xml inside the object objXmlRequestMessageDoc.
    The if statement I used in my function did not work. When it found Section element, it did not check for Subdivision. 
    How do I check for both and add them if they exist. If they do not exist, I do not need to do anything and should not throw an error since they are optional.
     Object aobjXmlGetStatuteRequestNode has this xml
    <ns:GetStatutesRequest xmlns:ns="http://www.courts.state.mn.us/StatuteService/1.0">
    <ns:Statute>
    <ns:Chapter>169</ns:Chapter>
    <!--Optional:-->
    <ns:Section>191</ns:Section>
    <!--Optional:-->
    <ns:Subdivision>a</ns:Subdivision>
    </ns:Statute>
    The following output in the objXmlRequestMessageDoc object is correct but this does not work when Section and or Subdivision are not found in the object aobjXmlGetStatuteRequestNode.
    <ns:BasicSearchQueryRequest xmlns:ns="http://crimnet.state.mn.us/mnjustice/statute/service/4.0">
    <ns1:BasicSearchCriteria xmlns:ns1="http://crimnet.state.mn.us/mnjustice/statute/messages/4.0">
    <ns2:Chapter xmlns:ns2="http://crimnet.state.mn.us/mnjustice/statute/4.0"/169</ns2:Chapter>>
    <ns2:Section xmlns:ns2="http://crimnet.state.mn.us/mnjustice/statute/4.0"/>191</ns2:Chapter>
    <ns2:Subdivision xmlns:ns2="http://crimnet.state.mn.us/mnjustice/statute/4.0"/>a</ns2:Chapter>
    </ns1:BasicSearchCriteria>
    </ns:BasicSearchQueryRequest>
    My Function
    Function GetStatutesByChapter(ByVal aobjXmlGetStatuteRequestNode As XmlNode, ByVal aobjXMLNameSpaceManager As XmlNamespaceManager, ByVal aobjBroker As ServiceCatalog.Library.v4.Broker) As XmlDocument
    Dim objXmlRequestMessageDoc As XmlDocument
    Dim objXmlResponseMessageDoc As XmlDocument
    Dim intCount As Integer
    aobjBroker.PostMessageWarehouseInformationalMessage("Chapter found.", 1)
    objXmlResponseMessageDoc = New XmlDocument
    'Add the first element into the document GetStatuteByChapter with its namespace
    objXmlResponseMessageDoc.AppendChild(objXmlResponseMessageDoc.CreateElement("BasicSearchQueryResponse", "http://crimnet.state.mn.us/mnjustice/statute/service/4.0"))
    'Create the BCA request message
    objXmlRequestMessageDoc = New XmlDocument
    objXmlRequestMessageDoc.AppendChild(objXmlRequestMessageDoc.CreateElement("ns:BasicSearchQueryRequest", aobjXMLNameSpaceManager.LookupNamespace("ns")))
    objXmlRequestMessageDoc.SelectSingleNode("ns:BasicSearchQueryRequest", aobjXMLNameSpaceManager).AppendChild(objXmlRequestMessageDoc.CreateElement("ns1:BasicSearchCriteria", aobjXMLNameSpaceManager.LookupNamespace("ns1")))
    objXmlRequestMessageDoc.SelectSingleNode("ns:BasicSearchQueryRequest/ns1:BasicSearchCriteria", aobjXMLNameSpaceManager).AppendChild(objXmlRequestMessageDoc.CreateElement("ns2:Chapter", aobjXMLNameSpaceManager.LookupNamespace("st")))
    objXmlRequestMessageDoc.SelectSingleNode("ns:BasicSearchQueryRequest/ns1:BasicSearchCriteria", aobjXMLNameSpaceManager).AppendChild(objXmlRequestMessageDoc.CreateElement("ns2:Section", aobjXMLNameSpaceManager.LookupNamespace("st")))
    objXmlRequestMessageDoc.SelectSingleNode("ns:BasicSearchQueryRequest/ns1:BasicSearchCriteria", aobjXMLNameSpaceManager).AppendChild(objXmlRequestMessageDoc.CreateElement("ns2:Subdivision", aobjXMLNameSpaceManager.LookupNamespace("st")))
    objXmlRequestMessageDoc.DocumentElement.SelectSingleNode("ns1:BasicSearchCriteria/st:Chapter", aobjXMLNameSpaceManager).InnerText = aobjXmlGetStatuteRequestNode.SelectSingleNode("ss:Statute/ss:Chapter", aobjXMLNameSpaceManager).InnerText
    objXmlRequestMessageDoc.DocumentElement.SelectSingleNode("ns1:BasicSearchCriteria/st:Section", aobjXMLNameSpaceManager).InnerText = aobjXmlGetStatuteRequestNode.SelectSingleNode("ss:Statute/ss:Section", aobjXMLNameSpaceManager).InnerText
    objXmlRequestMessageDoc.DocumentElement.SelectSingleNode("ns1:BasicSearchCriteria/st:Subdivision", aobjXMLNameSpaceManager).InnerText = aobjXmlGetStatuteRequestNode.SelectSingleNode("ss:Statute/ss:Subdivision", aobjXMLNameSpaceManager).InnerText
    'check if there is a section and or subdivision if it is there then set the value
    'If Not (aobjXmlGetStatuteRequestNode.SelectSingleNode("ss:Statute/ss:Section", aobjXMLNameSpaceManager).InnerText) Is Nothing Then
    ' objXmlRequestMessageDoc.DocumentElement.SelectSingleNode("ns1:BasicSearchCriteria/st:Section", aobjXMLNameSpaceManager).InnerText = aobjXmlGetStatuteRequestNode.SelectSingleNode("ss:Statute/ss:Section", aobjXMLNameSpaceManager).InnerText
    'End If
    'check if there is a section and or subdivision if it is there then set the value
    aobjBroker.PostMessageWarehouseSnapshot(objXmlRequestMessageDoc.OuterXml, "Request Message", 1)
    'Call the BCA service
    intCount = 0
    'Count how many Statute node found
    CType(objXmlResponseMessageDoc.SelectSingleNode("ss:GetStatutesResponse/ss:StatutesXml/ss:Statutes", aobjXMLNameSpaceManager), System.Xml.XmlElement).SetAttribute("totalCount", CStr(intCount))
    Return objXmlResponseMessageDoc
    End Function

    I have resolved this issue by using two if statements as follows
    'check if there is a section and or subdivision if it is there then set the value
    If Not (aobjXmlGetStatuteRequestNode.SelectSingleNode("ss:Statute/ss:Section", aobjXMLNameSpaceManager) Is Nothing) Then
    objXmlRequestMessageDoc.DocumentElement.SelectSingleNode("ns1:BasicSearchCriteria/st:Section", aobjXMLNameSpaceManager).InnerText = aobjXmlGetStatuteRequestNode.SelectSingleNode("ss:Statute/ss:Section", aobjXMLNameSpaceManager).InnerText
    End If
    If Not (aobjXmlGetStatuteRequestNode.SelectSingleNode("ss:Statute/ss:Subdivision", aobjXMLNameSpaceManager) Is Nothing) Then
    objXmlRequestMessageDoc.DocumentElement.SelectSingleNode("ns1:BasicSearchCriteria/st:Subdivision", aobjXMLNameSpaceManager).InnerText = aobjXmlGetStatuteRequestNode.SelectSingleNode("ss:Statute/ss:Subdivision", aobjXMLNameSpaceManager).InnerText
    End If

  • How do I check if the associated PageItem is there/exists from a XMLElement ?

    Hi,
    I have the following structure:
    Extension Builder 1.5;
    InDesign 5.0;
    Image (Rectangule Frame);
    XML tag associated with the Image.
    The following scenario:
    I do have an application that checks if this strucuture is available and intact, that is, the user has not deleted the tag (XMLElement) and/or the Rectangule Frame(PageItem);
    I do not want loop through allPageItems (the page should have many of them - more than 1000) and get the XMLElement;
    So, I loop over the XMLElements and get the associated PageItem through xmlElement.xmlContent property;
    The document images properties (image, epss, etc) never are populated (document.epss.length = 0);
    I can validate if the tag was deleted or untaged easy.
    The problem:
    User deletes the Image/Rectangule Frame (PageItem) and keep the xml tag (untag the XMLElement);
    The isValid property (xmlElement.isValid = true) is true;
    The associated PageItem becomes a Text and is valid as well;
    The question:
    How do I check if the associated PageItem is there/exists from a XMLElement ?
    Regards
    Marcos

    Found it, I think
        e.isControlDown()

  • How do you check the existance of a file in Linux?

    Hi,
    How do you check to see if a file in certain directory exists?
    I'm trying something like.
    if [ "ls fhs_jwesha_2.log" ]; then echo Here; else echo Not Here.;fibut I know that's not the right command.
    Anybody?

    Assuming from command line:
    [user@myhost /]$ [ -f /etc/passwd ] && echo "here" || echo "not here"
    here
    [user@myhost /]$ [ -f /etc/no_file ] && echo "here" || echo "not here"
    not hereFor a script, try:
    if [ -f /etc/passwd ]; then echo "here" ; else echo "not here" ; fi-troy
    http://troysunix.blogspot.com

  • How do I make my already existing check boxes "checkable" [so I can check and uncheck them on PDF Expert]

    How do I make my already existing check boxes on a (PDF Document) checkable - So I can check and uncheck them on PDF Expert or Annotate 101.
    I am using ADOBE Acrobat PRO with millions of options, but no easy "here is how to do the one thing you want to do" anywhere within reason.
    Please help me.
    Thank You

    Can you check and uncheck the boxes in Acrobat?

  • How do I check to see if a channel group exists in the data portal?

    I have a list of channel groups in the data portal but sometimes some channel groups  are not created all the time.  How do I check using a script if a channel group exists or was created.

    Hello jreynolds!
    With the command 'GroupIndexGet'. It returns 0 if the group does not exist.
    Matthias
    Matthias Alleweldt
    Project Engineer / Projektingenieur
    Twigeater?  

  • How to check any directory existance in TestStand?

    How to check any directory existance in TestStand?
    Is there TestStand function? Or other option without writing my own code in external program (e.g. LabVIEW or C)?
    Thanks in advance
    Solved!
    Go to Solution.

    At Least according to the NI TestStand 2012 documentation, Engine.FindPath and Engine.FindFile work only within the NI TestStand SearchDirectories.
    Maybe related: remote paths (\\server\path\to\file.ext) are considered "invalid" by Engine.FindPath.

  • How  to check  table have  exists any views in oracle

    hi,
    how to check table have exists any views in oracle

    SELECT * FROM user_dependencies
    WHERE type='VIEW'
    AND referenced_type='TABLE'
    AND referenced_name ='Your_Table_Name' You may use dba_dependencies to find views in different schema.

  • How to check one table exist or not in SAP

    Hi, Gurus:
    How to check one table exist or not in the SAP.
    Thanks,

    Hi,
    Query the table DD02L..
    Select single * from DD02L where tabname = 'Your table name'
                          AND TABCLASS = 'TRANSP'.  " For transparent tables.
    Thanks
    Naren

  • How to check whether file exist or not?

    hello,
    i wanted to know that how can i check whether a file exist or not independent of underlying Operating system?
    please help .
    Thank you.

    Use exists() on a File instance.

  • Newbie qn - How do I check if a schema exists?

    Hi,
    Sorry for askin a stupid qn.
    How do I check if a particular schema exists?
    Is schema the same as a user?
    Thanks,
    Mel

    After going through other messages I think I have found the answer to my qn.
    I guess connecting to sql*plus with the schema name proves that the schema exists. Can someone confirm this?
    Thanks,
    Mel

  • How can I check existing Macbook come with G5 or Intel cpu

    Hi,
    I got the Macbook from my friend, they forgot the cpu model and the hd is out of order, how can I check the MacBook cpu type as I am afraid the HD compatibility problem if I buy the hd for replacement, thanks.
    patrick

    All MacBooks are Intel CPUs and all MacBooks use a SATA hard drive.
    For a hard drive try Newegg.com  http://www.newegg.com/Store/SubCategory.aspx?SubCategory=380&name=Laptop-Hard-Dr ives&Order=PRICE
    Or OWC  http://eshop.macsales.com/shop/hard-drives/2.5-Notebook/
    Here are instructions on replacing the hard drive in a MacBook with a removable battery.  http://creativemac.digitalmedianet.com/articles/viewarticle.jsp?id=45088
    Here's a list of all the MacBooks made http://www.everymac.com/systems/apple/macbook/index-macbook.html

Maybe you are looking for

  • Incoming calls are going directly to Voicemail, Iphone 5S

    I switched phones from an Iphone 4 to this Iphone 5S and my incoming calls are going directly to voice-mail and not ringing the phone. The only app I downloaded that is different from my Iphone 4 is the GroupMe app, but I don't know if that is necess

  • Custom Page Sizes - How to change from centimeters to Inches?

    Hello, I'm working on some panoramic prints to an Epson R2400 and I need to set up a custom paper size for printing to roll paper. When I select Custom Page Sizes from the Page Setup dropdown, all my measurements are forced into centimeters. Even if

  • Missile Command widget

    While this new widget is fun, it eats up CPU capacity, even when not playing!  My Mac Mini was running hot (fan going fast) and I didn't have that much open, so I opened Activity Monitor and found that the widget was using 30% of the CPU, and I wasn'

  • Changing init.ora file

    Hi, I need to add the utl_file_dir parameter to the init.ora file. Do I need to restart the database for the changes to be effective? My oracle version is Oracle9i Enterprise Edition Release 9.2.0.8.0 - Production With the Partitioning, OLAP and Orac

  • Apple id vs ICloud Account ?

    We have changed our Apple Id and now I can not turn off 'FInd my Phone' as it is still registering as the old id.  I am having issues with phone and need to back up and restore.  Can anyone help me change my account (apple id) on ICloud??  Thanks