使用方法动态sql中的表名中的(&)字符? [英] How to use & (ampersand) character in table name in dynamic sql?

查看:61
本文介绍了使用方法动态sql中的表名中的(&)字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用动态SQL从一组表中进行选择,其中某些表名包含&"特点.但是,一旦我的查询命中了这些表之一,我就会收到以下错误:

I am using dynamic SQL to Select from a group of tables where some of the table names contain the '&' character. However once my query hits one of these tables I get the following error:

'&'附近的语法不正确.

Incorrect syntax near '&'.

以下是一些示例代码,可重新创建我遇到的错误:

Here is some example code that recreates the error I am getting:

DECLARE @TABLE_NAME AS NVARCHAR(150);
SET @TABLE_NAME = 'A&BTable';

EXEC(
    'SELECT col1, col2, col3
     FROM Warehouse_Repository.dbo.' + @TABLE_NAME
)

如何更改此查询,以便可以从包含&"的表名称中进行选择使用动态SQL?

How can I alter this query so that I can Select from table names containing '&' using dynamic SQL?

推荐答案

添加 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆