英文:
SQL Server EXEC misinterpreting database name
问题
这部分的翻译如下:
This: @query = `SELECT Count(*) FROM ReportServer$DEVSVR1.INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'`
executes fine if copied into new query window. But fails EXEC @query with this error:
> Database 'SELECT Count(*) FROM ReportServer$DEVSVR1' does not exist.
SQL is incorrectly parsing the phrase 'SELECT Count(*) FROM ReportServer$DEVSVR1'
as the database name.
翻译成中文为:
这段代码:@query = `SELECT Count(*) FROM ReportServer$DEVSVR1.INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'`
如果复制到新的查询窗口中执行是正常的。但是使用EXEC @query时会出现以下错误:
> 数据库 'SELECT Count(*) FROM ReportServer$DEVSVR1' 不存在。
SQL错误地将短语 'SELECT Count(*) FROM ReportServer$DEVSVR1' 解析为数据库名称。
英文:
This: @query = SELECT Count(*) FROM ReportServer$DEVSVR1.INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'
executes fine if copied into new query window. But fails EXEC @query with this error:
> Database 'SELECT Count(*) FROM ReportServer$DEVSVR1' does not exist.
SQL is incorrectly parsing the phrase 'SELECT Count(*) FROM ReportServer$DEVSVR1'
as the database name.
答案1
得分: 0
EXEC @query 意味着执行存储过程,该存储过程的名称在 @query 变量中。
您可能想要使用 EXEC(@query) 来执行字符串。
英文:
EXEC @query means execute procedure with name that is in @query variable.
You probably want EXEC(@query) which executes the string
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论