Incorrect Syntax near tempdb

  • Hi,

    I am getting the below error for a query that runs inside the SSIS package. The Query does not have the symbol 'A'. Not sure from where that A is coming and erroring out the query. Please let me know your thoughts.

    Error: Merge query to load sample to demo :Error: Executing the query "IFÂ OBJECT_ID('tempdb..##tmp')Â ISÂ NOTÂ NULL

    Â Â ..." failed with the following error: "Incorrect syntax near 'tempdb..##tmp'.".

    query:

    IF OBJECT_ID('tempdb..##tmp') IS NOT NULL

    /*Then it exists*/

    DROP TABLE ##tmp

  • Can it be space or hidden character issue? I dont see anything when I paste this in notepad.

  • Try

    DROP TABLE IF EXISTS ##tmp

    instead.

    • This reply was modified 2 years, 9 months ago by  Phil Parkin.
    • This reply was modified 2 years, 9 months ago by  Phil Parkin.

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • For fun, I tried running the query you had pasted and it runs fine on my system.

    My guess is you copy-pasted that from another site that does some formatting on the text.  My expectation is that wherever you copy-pasted it from it throws in some hidden characters that are used for colorizing the text or providing some level of formatting.

    I would try either:

    A - typing it out manually into SSMS and see if you get the same error

    B - copy and paste the text into a text editor that won't retain formatting such as Notepad

    Alternately, if you are copy-pasting or running a SQL query generated on Windows on a Linux machine (or generated on Linux and running on Windows), you will have different line terminators which MAY be causing some of the issues.  Same thing applies to MAC if I remember right...

    The above is all just my opinion on what you should do. 
    As with all advice you find on a random internet forum - you shouldn't blindly follow it.  Always test on a test server to see if there is negative side effects before making changes to live!
    I recommend you NEVER run "random code" you found online on any system you care about UNLESS you understand and can verify the code OR you don't care if the code trashes your system.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply