I was going to check if a temp table exists and delete the it,since "the temptable already exists" arises if you want to perform another operation.
Here's the code i used five statements but it says syntax error in drop table or drop index statement.
Any help would be appreciated.

"DROP TABLE IF EXISTS LIKE 'prtempTable%'"
"DROP TABLE IF EXISTS LIKE '%prtempTable%'"
"DROP TABLE IF EXISTS WHERE TABLE LIKE 'prtempTable%'"
"DROP TABLE LIKE 'prtempTable%'"
"DROP TABLE LIKE '%prtempTable%'"

Recommended Answers

All 6 Replies

Try

IF OBJECT_ID('myTable','U') IS NOT NULL DROP TABLE myTable

Does this work on access database?

I've never tried it on an Access database. I suggest you create a dummy table and try it out.

It doesn't work,since it's for sql server db.Is there another way to solve it?

How about just putting the delete code in a Try-Catch block and seeing what error occurs if the table does not exist? That will tell you what error to ignore.

I used this sub procedure and it worked fine.

On Error GoTo ErrorHandler
        Dim str As String
        str = "DROP TABLE ptempTable"
        ExecSQL(str)
        Exit Sub
ErrorHandler:
        If Err.Number = 7874 Then
            Resume Next
        End If

Thanks by the way

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.