• kinderdesign (8/29/2012)


    Most columns are identical and this is what I'm traying to make a report of. Is there a way to grab all current tables in the db with columns like '%Inspection' and get all of the unique columns too? Any help would be GREATLY appreciated!

    While you could find all the tables with the name you want (sys.systables and sys.syscolumns), you're going to run into a problem trying to union them together.

    The first select in the union will control your column count and the underlying datatypes. You won't be able to alter it after the first select. You'll be able to put together all the identitical columns, but you won't be able to include all the unique ones underneath without creating a 'shell' column of some kind in the first query.

    You'll end up having to make enough varchar() columns to cover all eventual possibilities, fill the blanks in when they're not used, and convert anything else into varchar() and drop it into the placeholder columns. Because of that, you won't want to automate the independents, you're going to have to account for them very particularly.


    - Craig Farrell

    Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

    For better assistance in answering your questions[/url] | Forum Netiquette
    For index/tuning help, follow these directions.[/url] |Tally Tables[/url]

    Twitter: @AnyWayDBA