Skip to content

Commit

Permalink
BrentOzarULTD#293 Support for @OutputServerName
Browse files Browse the repository at this point in the history
Some cleanup and renaming things to be more clear. I couldn't get rid of
the output from the linked server DB check without dumping the results
to a temp table and reading them from there. It's only a single cell
with a 1, but I felt kinda dirty doing it. I tried everything though;
dynamic linked server queries don't play nice with local variables or
OUTPUT.
  • Loading branch information
Haris Khan authored and Haris Khan committed Jul 19, 2016
1 parent a55f396 commit 1d8730e
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions sp_Blitz.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5692,15 +5692,16 @@ IF @ProductVersionMajor >= 10 AND NOT EXISTS ( SELECT 1
DECLARE @ValidOutputServer BIT
DECLARE @ValidOutputLocation BIT
DECLARE @LinkedServerDBCheck NVARCHAR(2000)
DECLARE @Count INT
DECLARE @ValidLinkedServerDB INT
DECLARE @tmpdbchk table (cnt int)
IF @OutputServerName IS NOT NULL
BEGIN
IF EXISTS (SELECT server_id FROM sys.servers WHERE QUOTENAME([name]) = @OutputServerName)
BEGIN
SET @LinkedServerDBCheck = 'SELECT * FROM '+@OutputServerName+'.master.sys.databases WHERE QUOTENAME([name]) = '''+@OutputDatabaseName+''''
EXEC sys.sp_executesql @LinkedServerDBCheck
SELECT @Count = @@ROWCOUNT
IF (@Count > 0)
SET @LinkedServerDBCheck = 'SELECT 1 WHERE EXISTS (SELECT * FROM '+@OutputServerName+'.master.sys.databases WHERE QUOTENAME([name]) = '''+@OutputDatabaseName+''')'
INSERT INTO @tmpdbchk EXEC sys.sp_executesql @LinkedServerDBCheck
SET @ValidLinkedServerDB = (SELECT COUNT(*) FROM @tmpdbchk)
IF (@ValidLinkedServerDB > 0)
BEGIN
SET @ValidOutputServer = 1
SET @ValidOutputLocation = 1
Expand Down

0 comments on commit 1d8730e

Please sign in to comment.