Suppose I have a query stored in a variable like this (it\'s actually dynamically populated and more complex, but this is for demonstration purposes):
DECLAR
You can use EXEC to execute sql statement, then call @@ROWCOUNT which Returns the number of rows affected by the last statement, to check row exists in sql select stetement.
DECLARE @Query VARCHAR(1000) = 'SELECT * FROM dbo.MyTable',@hasRow int
EXEC (@Query)
SELECT @hasRow =@@ROWCOUNT // Returns the number of rows affected by the last statement
PRINT @hasRow
IF @hasRow > 0
BEGIN
Print 1
END
BEGIN
Print 2
END