我正在尝试在 sql server 查询 where 子句中使用 sqsh 变量,但无法使其工作。以下是我面临的问题的简单模拟。有人可以帮我解决这个问题吗
这按预期工作
select * from information_schema.tables where table_name = 'PHONES';
但以下将不起作用
\set tableName=PHONES;
select * from information_schema.tables where table_name = $tableName;
Error Message:: Invalid column name 'PHONES'
select * from information_schema.tables where table_name = '$tableName';
No rows are returned as it searches for a table $tableName
select * from information_schema.tables where table_name = "$tableName";
Error Message:: Invalid column name 'PHONES'.