>Let say I have a database in Sql Server with about 20 tables in it, and that most of those tables have a field "qty".
>
>How could I write query that says
>
>" For each table in the database where the table has a column named 'qty'
> Select table_name, Max(qty) as max_qty "
>
>
>
>Basically, I need a cursor that shows the tablename and the Max(qty) from that table.
>
>BTW it doesn't matter to me whether this is code I from FoxPro or in Sql Server Mgmt Studio.
You can generate the script dynamically using INFORMATION_SCHEAM.Columns view.
I have a blog post on
www.lessthandot.com that shows samples of such scripts.
If it's not broken, fix it until it is.
My Blog