I hope this is not a tricky one...
I am building a stored procedure which will go through some table in SQL 2000 database to build a table that shows field names from multiple tables and the count of the distinct values
my script is something like this
SELECT @sSQL = 'select distinct(Field1) Field1, count(*) counter from Table1
group by Field1
select distinct(Field1) Field1, count(*) counter from Table2
group by Field1'
EXEC sp_executesql @sSQL
Now my issue is that at some cases the required field would not be in Table1 or In table2 but for sure it is in one of the tables at least...
So How can I add a validation into my script