Skip to main content
formatted code to remove horizontal scroll
Source Link
Nick Chammas
  • 14.8k
  • 17
  • 76
  • 123

If I want to query all databases on a server to see if a stored procedure is present, I can combine a sp_executesql and run a cursor over a query similar to the following:

SELECT 
     'select ' + '''' + name + '''' + ', name from [' + name 
   + '].sys.procedures WHERE name = ''usp_MyProc'' COLLATE SQL_Latin1_General_CP1_CI_AI ' 
    FROM sys.databases 
    -- I get a collation error from the following
    WHERE name NOT IN ('ReportServer', 'ReportServerTempDb');

Can I do the same thing without dynamic sql and without the cursor?

If I want to query all databases on a server to see if a stored procedure is present, I can combine a sp_executesql and run a cursor over a query similar to the following:

SELECT 'select ' + '''' + name + '''' + ', name from [' + name + '].sys.procedures WHERE name = ''usp_MyProc'' COLLATE SQL_Latin1_General_CP1_CI_AI ' 
    FROM sys.databases 
    -- I get a collation error from the following
    WHERE name NOT IN ('ReportServer', 'ReportServerTempDb')

Can I do the same thing without dynamic sql and without the cursor?

If I want to query all databases on a server to see if a stored procedure is present, I can combine a sp_executesql and run a cursor over a query similar to the following:

SELECT 
     'select ' + '''' + name + '''' + ', name from [' + name 
   + '].sys.procedures WHERE name = ''usp_MyProc'' COLLATE SQL_Latin1_General_CP1_CI_AI ' 
FROM sys.databases 
-- I get a collation error from the following
WHERE name NOT IN ('ReportServer', 'ReportServerTempDb');

Can I do the same thing without dynamic sql and without the cursor?

Tweeted twitter.com/#!/StackDBAs/status/175956166151634945
added 57 characters in body
Source Link
Justin Dearing
  • 2.7k
  • 6
  • 36
  • 52

If I want to query all databases on a server to see if a stored procedure is present, I can combine a sp_executesqlsp_executesql and run a cursor over a query similar to the following:

SELECT 'select ' + '''' + name + '''' + ', name from [' + name + '].sys.procedures WHERE name = ''usp_MyProc'' COLLATE SQL_Latin1_General_CP1_CI_AI ' 
    FROM sys.databases 
    -- I get a collation error from the following
    WHERE name NOT IN ('ReportServer', 'ReportServerTempDb')

Can I do the same thing without dynamic sql and without the cursor?

If I want to query all databases on a server to see if a stored procedure is present, I can combine a sp_executesql and run a cursor over a query similar to the following:

SELECT 'select ' + '''' + name + '''' + ', name from [' + name + '].sys.procedures WHERE name = ''usp_MyProc'' COLLATE SQL_Latin1_General_CP1_CI_AI ' 
    FROM sys.databases 
    -- I get a collation error from the following
    WHERE name NOT IN ('ReportServer', 'ReportServerTempDb')

Can I do the same thing without dynamic sql and without the cursor?

If I want to query all databases on a server to see if a stored procedure is present, I can combine a sp_executesql and run a cursor over a query similar to the following:

SELECT 'select ' + '''' + name + '''' + ', name from [' + name + '].sys.procedures WHERE name = ''usp_MyProc'' COLLATE SQL_Latin1_General_CP1_CI_AI ' 
    FROM sys.databases 
    -- I get a collation error from the following
    WHERE name NOT IN ('ReportServer', 'ReportServerTempDb')

Can I do the same thing without dynamic sql and without the cursor?

Source Link
Justin Dearing
  • 2.7k
  • 6
  • 36
  • 52

Can I query stored procs in all databases with one query without dynamic sql

If I want to query all databases on a server to see if a stored procedure is present, I can combine a sp_executesql and run a cursor over a query similar to the following:

SELECT 'select ' + '''' + name + '''' + ', name from [' + name + '].sys.procedures WHERE name = ''usp_MyProc'' COLLATE SQL_Latin1_General_CP1_CI_AI ' 
    FROM sys.databases 
    -- I get a collation error from the following
    WHERE name NOT IN ('ReportServer', 'ReportServerTempDb')

Can I do the same thing without dynamic sql and without the cursor?