我想查询一个SQL Server实例,给我一个包含特定名称表的数据库列表。这是我迄今为止...有没有办法在where子句中使用`exec`?
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子句中正确的语法?还是有另一种方法来做我想做的事情?
嗯有点比我的短一点 – 2012-04-16 16:19:47