How to not show results of queries that return zero records

  • My client has a SQL Server 2008 R2 instance with an accounting package that is using a third party archiving product to remove historical records out of the live database and into an archive database. I'm trying to verify that the data has been moved correctly out of about 150 tables because I've been getting SQL errors but the third party is not helpful in resolving them. I'd like to run queries on all of the tables on the live database to verify that the data no longer exists. Is there a way to run all of the select statements at the same time but only show the results of the select statements that return records and not the headers of the queries that return zero reccords?

    For example, if I run the following select statements, 2 of these 8 queries return results. Is there a way to only return the results of those 2 queries and not show the results (field names) of the other 6 queries that show no records? And is there also a way to put the name of the table in the query results?

    select * from gl30000 where trxdate <='12/31/1993' --Account Transaction History

    select * from cm20400 where GLPOSTDT <='12/31/1993' --CM Distribution

    select * from cm20100 where CMDNUMWK in (select CMDNUMWK from CM20400 where GLPOSTDT <='12/31/1993') --CM Journal

    select * from cm20300 where GLPOSTDT <='12/31/1993' --CM Receipt

    select * from cm20501 where GLPOSTDT <='12/31/1993' --CM Reconcile Adjustments

    select * from cm20500 where GLPOSTDT <='12/31/1993' and RECONUM in (select RECONUM from cm20501 where GLPOSTDT <='12/31/1993') --CM Reconcile Header

    select * from cm20200 where GLPOSTDT <='12/31/1993' --CM Transaction

    select * from cm20400 where GLPOSTDT <='12/31/1993' --CM Transmission Log

    Thanks for your help!

  • if exists(select 1 from Table1) select * from Table1;

  • That does the trick. Thank you!!!

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply