更新时间:2023-02-03 18:25:33
您可以将表名包含在[]
SET @sql= N' select * from [' + @tblname + '] where name= @param1 and id= @param2';
但是,如果您使用由两部分组成的命名约定,例如dbo.tablename
,则您必须添加其他解析,因为[dbo.tablename]
会导致:
However, if you use a two-part naming convention e.g dbo.tablename
, you have to add additional parsing, since [dbo.tablename]
will result to:
无效的对象名称[dbo.tablename].
Invalid object name [dbo.tablename].
您应该对其进行解析,以使其等于dbo.[tablename]
.
You should parse it so that it'll be equal to dbo.[tablename]
.