You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

执行MSSQL跨库查询报错:关键字'AS'附近语法不正确,求协助

Fixing the "Incorrect syntax near the keyword 'AS'" Error in SQL Server

Hey there, let's sort out this issue quickly—your problem stems from using AS as a database name, and AS is a reserved keyword in SQL Server. When you use reserved keywords directly as object names (like databases, tables, or columns), SQL Server gets confused because it expects that keyword to serve its built-in purpose (like creating aliases with AS).

The Simple Fix

Wrap the reserved keyword database name in square brackets [] to tell SQL Server to treat it as a literal object name instead of a keyword. Here's your corrected query:

select * from [AS].dbo.MULTIPLE_SUBSCRIBERS

Why This Works

Square brackets are SQL Server's standard way to escape reserved words or object names that include special characters, spaces, or match built-in keywords. You could also use double quotes if your database has QUOTED_IDENTIFIER enabled, but square brackets are the more universally compatible approach across most SQL Server setups.

Run that adjusted query, and you should be able to access your table without hitting the syntax error anymore!

内容的提问来源于stack exchange,提问作者Venkatesh K

火山引擎 最新活动