我正在尝试查询 SQL Server 的实例,以给我一个包含特定名称表的数据库列表。这是我目前所拥有的......
select name
from master..sysdatabases
where (exec('use ' + name + '; select 1 from information_schema.tables
where table_name = ''TheTableName'';')) = 1;
但我收到以下错误消息
Msg 156, Level 15, State 1, Line 4
Incorrect syntax near the keyword 'exec'.
Msg 102, Level 15, State 1, Line 4
Incorrect syntax near 'name'.
exec()
在 where 子句中使用 call 的正确语法是什么?还是有另一种方法可以做我想做的事情?