Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Incorrect syntax near ''

I'm trying to run the following fairly simple query in SQL Server Management Studio:

SELECT TOP 1000 *  FROM      master.sys.procedures as procs left join      master.sys.parameters as params on procs.object_id = params.object_id 

This seems totally correct, but I keep getting the following error:

Msg 102, Level 15, State 1, Line 6
Incorrect syntax near ''.

It works if I take out the join and only do a simple select:

SELECT TOP 1000 * FROM      master.sys.procedures as procs 

But I need the join to work. I don't even have the string '' in this query, so I can't figure out what it doesn't like.

like image 643
Joshua Frank Avatar asked Nov 01 '13 15:11

Joshua Frank


People also ask

What is near Error SQL?

Overview. This SQL error generally means that somewhere in the query, there is invalid syntax. Some common examples: Using a database-specific SQL for the wrong database (eg BigQuery supports DATE_ADD, but Redshift supports DATEADD)

What does Incorrect syntax mean in SQL?

The most common SQL error is a syntax error. What does syntax mean? Basically, it means a set arrangement of words and commands. If you use improper syntax, the database does not know what you're trying to tell it.

Where is SQL?

The SQL WHERE clause is used to specify a condition while fetching the data from a single table or by joining with multiple tables. If the given condition is satisfied, then only it returns a specific value from the table. You should use the WHERE clause to filter the records and fetching only the necessary records.

What is invalid object name in SQL?

This typically means 1 of 2 things... you've referenced an object (table, trigger, stored procedure,etc) that doesn't actually exist (i.e., you executed a query to update a table, and that table doesn't exist). Or, the table exists, but you didn't reference it correctly...


2 Answers

Such unexpected problems can appear when you copy the code from a web page or email and the text contains unprintable characters like individual CR or LF and non-breaking spaces.

like image 125
Panagiotis Kanavos Avatar answered Sep 21 '22 20:09

Panagiotis Kanavos


Panagiotis Kanavos is right, sometimes copy and paste T-SQL can make appear unwanted characters...

I finally found a simple and fast way (only Notepad++ needed) to detect which character is wrong, without having to manually rewrite the whole statement: there is no need to save any file to disk.

It's pretty quick, in Notepad++:

  • Click "New file"
  • Check under the menu "Encoding": the value should be "Encode in UTF-8"; set it if it's not
  • Paste your text enter image description here
  • From Encoding menu, now click "Encode in ANSI" and check again your text enter image description here

You should easily find the wrong character(s)

like image 29
MAXE Avatar answered Sep 24 '22 20:09

MAXE