Hi
I am a database expert with 15 years experience in handling MS SQL databases. I have worked as DBA for large ERP databases and use to write and do performance tuning for SQL queries, procedures and triggers.
I have a few questions, basically to make sure I understand the requirement well. You mentioned that you have 100 databases, and don't you want to set the billing for all 100? In the script I see only a few databases like Adair, NITkootenai, Elbert etc.
If you want all 100 to be done, an easy option to make the script not long is to put all database names in a table and then loop this table to generate 100 SQL statements.
To find the usage are you looking only at the two tables tbldocumentinfo and tbluserfield? These two tables are uniform across all databases? No need to consider any other tbales in these databases? If so, you already have written the script to get the count from these tables. May be another looping to generate 100 update statements each should do the job? Or can you tell me what exactly is not working with your current script.
Thanks
Roni