From 1d8730ed1a3d241e2070ea47ad92a4d46a035649 Mon Sep 17 00:00:00 2001 From: Haris Khan Date: Tue, 19 Jul 2016 18:59:36 -0400 Subject: [PATCH] #293 Support for @OutputServerName 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. --- sp_Blitz.sql | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/sp_Blitz.sql b/sp_Blitz.sql index b1b1b05b8..1c3b8b3ff 100755 --- a/sp_Blitz.sql +++ b/sp_Blitz.sql @@ -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