An observation on the code you presented - when I paste it into a query window I get errors
Quote:
Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'SELECT'.
Msg 102, Level 15, State 1, Line 2
Incorrect syntax near 'IsFullTextInstalled'.
Those extra double quotes at the start and end of the code should not be there. If removed the code produces the text
SELECT CASE SERVERPROPERTY(''IsFullTextInstalled'')
WHEN 1 THEN
CASE DatabaseProperty (DB_NAME(DB_ID()), ''IsFulltextEnabled'')
WHEN 1 THEN 1
ELSE 0
END
ELSE 0
END
which still produces the error. I think the code should read
exec(
'SELECT CASE SERVERPROPERTY(''IsFullTextInstalled'')
WHEN 1 THEN
CASE DatabaseProperty (DB_NAME(DB_ID()), ''IsFulltextEnabled'')
WHEN 1 THEN 1
ELSE 0
END
ELSE 0
END
')
A technique I sometimes employ to avoid long streams of single quotes is to use
CHAR(39)
to represent the single quote that needs to be in the dynamic query E.g.
DECLARE @DynamicQuery Nvarchar(max) =
'SELECT CASE SERVERPROPERTY(' + CHAR(39) + 'IsFullTextInstalled' + CHAR(39) + ')
WHEN 1 THEN
CASE DatabaseProperty (DB_NAME(DB_ID()),' + CHAR(39) + 'IsFulltextEnabled' + CHAR(39) + ')
WHEN 1 THEN 1
ELSE 0
END
ELSE 0
END
'
EXEC sp_executesql @DynamicQuery