跨库查询、遍历数据库的范例

EXEC sp_MSforeachdb  @command1='IF ''?'' NOT IN(''master'', ''model'', ''msdb'', ''tempdb'',"ReportServer","ReportServerTempDB","OA系统") select min(issueDate) as MinDate,Max(issueDate) as MaxDate,DATEDIFF(day,'2008-12-29','2008-12-30') AS DiffDate from ?.dbo.SS_consume'

 

EXEC sp_MSforeachdb  @command1='命令'

@command2='命令'

你可能感兴趣的:(SQL,Server)