Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7036659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:27:02+00:00 2026-05-28T01:27:02+00:00

I’m looking to scrub data in migration project from a legacy system developed on

  • 0

I’m looking to scrub data in migration project from a legacy system developed on SQL Server 2005, but the first order of business is to figure out which columns aren’t really in use.

The general logic behind my approach is to identify columns that are mostly left blank (i.e., most or all rows contain null values, for that column, in that table). This would be executed as a stored procedure, where the ideal output would be something like:

TABLE: contacts (10000 records)
---------------------------------
FIELD: id | 0 (0%) Null Records
FIELD: username | 0 (0%) Null Records
FIELD: phonenumber | 8,200 (82%) Null Records
FIELD: email | 300 (3%) Null records
FIELD: icq | 9,900 (99%) Null Records
FIELD: zip | 100 (1%) Null Records

Here’s the catch: some tables have over 100 columns, so the real key is for the procedure to loop through the columns of a given table, so I don’t have to key in a long string of column names to run the query. Any help on how to do this would be great,

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:27:03+00:00Added an answer on May 28, 2026 at 1:27 am

    You can use the column metadata to create some queries like this:

    select 'select ''' + table_name + ''' table_name, ''' 
    + column_name + ''' column_name, count(*) nullcount '
    + 'from [' + table_name + '] where [' + column_name + '] is null '
    from information_schema.columns
    

    If you run the query above, you will get a list of select queries. Copy paste to a text editor and insert ‘union all’ between the selects, it will look like this:

    select 'companies' table_name, 'id' column_name, count(*) nullcount from [companies] where [id] is null 
    union all
    select 'companies' table_name, 'code' column_name, count(*) nullcount from [companies] where [code] is null 
    union all
    ...
    

    Then run those unioned selects.

    For list of tables, you can use the same trick with metadata in information_schema.tables.

    Then combine the two lists in excel using vlookup, or build a more complex queries with subqueries using information_schema.tables and information_schema.columns.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to construct a data frame in an Rcpp function, but when I
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.