I have read-only access to four SQL Server databases.
In each database roughly half of the tables have a column named [DIM_1].
I am interested in the number of times a particular string value (e.g. 'ABCD') appears in each of these columns.
I need a way to return a data table that looks like
DatabaseName, TableName, CountOfABCD
I tried initially to do this with a loop, but it was pretty horrible and I ran into the issue that you can't use a variable for a table name.
I'm wondering if there is anything I can do with sp_MSforeachtable but my database skills are falling a little short.
Would anyone have any suggestions? I've found scripts to create stored procedures that perform the task (e.g. http://vyaskn.tripod.com/search_all_columns_in_all_tables.htm ), but I can't create them because of my access level. They also use temp tables, which I also can't create.
Any thoughts gratefully received.
Thanks,
Tom