Toad World® Forums

SQL Database Error while creating the QUERY

I am getting a SQL Database Error while creating the QUERY having the database name starting with @Project.

i have attached the sceen sample of the Error FYI

Error:5/11/2020 12:56:25 PM 0:00:00.004: Lookup Error - SQL Server Database Error: Incorrect syntax near '@PRJEH'.
2:26: SELECT [@PRJEH].[DocEntry], [@PRJEH].[DocNum], [@PRJEH].[Instance]
FROM QICL_LIVE_2019_1.dbo.@PRJEH [@PRJEH]

I won't pretend to be a SQL Server expert, but I do know that "@" is a prefix used extensively when referring to functions/procedures, and also variable names. I'm surprised that SQL Server allows you to use the "@" symbol to name databases for this reason.

That said, you may need to bracket or quote the reference to your (entire) table name.

the regular rules for identifiers in mssql server are : for the first character :

The underscore (_), at sign (@), or number sign (#).

Certain symbols at the beginning of an identifier have special meaning in SQL Server. A regular identifier that starts with the at sign always denotes a local variable or parameter and cannot be used as the name of any other type of object. An identifier that starts with a number sign denotes a temporary table or procedure. An identifier that starts with double number signs (##) denotes a global temporary object. Although the number sign or double number sign characters can be used to begin the names of other types of objects, we do not recommend this practice.

Some Transact-SQL functions have names that start with double at signs (@@). To avoid confusion with these functions, you should not use names that start with @@.