Thomas

Thomas

  • NA
  • 41
  • 0

Stored procedure - Only return if rows > 0

Jun 22 2017 10:23 AM
Hi all. I have this stored procedure which executes a lot of sql queries and returns the results. How do i go about returning only the results from the queries that returns rows?
 
BEGIN
   DECLARE @Query varchar(4000)
   DECLARE cur CURSOR FOR SELECT SQLSyntax FROM tblChecks
 
   OPEN cur
   FETCH NEXT FROM cur INTO @Query
   WHILE @@FETCH_STATUS = 0 BEGIN
   EXEC (@Query)
   FETCH NEXT FROM cur INTO @Query
   END
   CLOSE cur
   DEALLOCATE cur
END
 

Answers (7)