I am running the following code to extract all relevant rows from all tables that have a particular column. The outer IF is supposed to check if the column exists o
exec sp_MSforeachtable
@command1='select * from ? where GCRecord is not null',
@whereand='and exists(select 1 from sys.columns c where c.object_id = o.id
and c.name = ''GCRecord'')'