TSQL script returning wrong result
Your problem might be related to issuing a USE inside of a cursor. Instead, I would suggest using the following approach, so you can get rid of the cursor.

EXEC sp_MSforeachdb 
'USE ? 
 IF ''?'' &lt;&gt; ''master'' AND ''?'' &lt;&gt; ''model'' AND ''?'' &lt;&gt; ''msdb'' AND ''?'' &lt;&gt; ''tempdb''
 BEGIN
      IF EXISTS(SELECT 1 FROM sys.indexes ind WHERE object_id = OBJECT_ID(''dbo.TestTable'') AND name = ''Test'') 
    PRINT ''Exists in '' + DB_NAME()  
ELSE 
    PRINT ''Not Exists in '' + DB_NAME()
END'


Please note that technically, sp_MSforeachdb is an undocumented feature but it simply works.