Hey Guys,SET @SQL = @SQL + ' IF (SELECT 1 FROM [' + @DATABASE + N']..SYSOBJECTS WHERE NAME = ''BASETABLE'') = 1 ' + N'AND ((SELECT 1 FROM ' + @DATABASE + N'..SYSOBJECTS WHERE NAME = ''UIDMAX'') = 1) ' + N'BEGIN SELECT 1 END ELSE BEGIN SELECT 0 END' --PRINT @SQL EXEC SP_EXECUTESQL @SQL, N'@OPENDB INT ', @OPENDB SET @SQL = ''
I have the above code in a cursor. I expect the variable @OPENDB to be set to either 1 or 0 (which it does) but I don't want the result to be displayed on my screen until I specify a PRINT @OPENDB command. At the moment I am getting the following in the result window :----------- 1... and this is repeated (because of the cursor).How do I turn this off? Or how do I just assign the result of the dynamic SQL statment to the variable without it being printed on the result screen?Thanks.BTW, I tried :SET @SQL = @SQL + ' IF (SELECT 1 FROM [' + @DATABASE + N']..SYSOBJECTS WHERE NAME = ''BASETABLE'') = 1 ' + N'AND ((SELECT 1 FROM ' + @DATABASE + N'..SYSOBJECTS WHERE NAME = ''UIDMAX'') = 1) ' + N'BEGIN SET @OPENDB = 1 END ELSE BEGIN SET @OPENDB = 0 END'
... but the @OPENDB variable is always 0 as if the dynamic statment is not changing the value of the variable if the IF condition evaluates to TRUE.----------------Shadow to Light