John Straka
John Straka

Reputation: 1914

Select names of columns that have no data in Access?

I'm working on a C# application that imports data from Access into SQL Server. They select an Access file, then a table in the file.

I then perform checks on the data to see if it's valid to import. I want to display a list of columns from the table that have no data in them, so the user has to confirm they want to import regardless of certain empty columns.

Is there an approach to this in Access besides looping through SELECT ... WHERE (field) IS NULL queries?

Upvotes: 3

Views: 432

Answers (2)

HansUp
HansUp

Reputation: 97101

Is there an approach to this in Access besides looping through SELECT ... WHERE (field) IS NULL queries?

I don't know of an alternative to looping, but I will suggest a different strategy for the queries you run in the loop. Seems to me you would want to know whether any rows include non-Null values for the given field.

SELECT Count(*) AS row_count
FROM Table_Name
WHERE field_name Is Not Null;

Upvotes: 1

Louis Ricci
Louis Ricci

Reputation: 21086

No looping necessary

  • Use Count(*) to get the number of total records
  • Use Count with WHERE (field) IS NULL and compare the counts
    • If the counts are equal all of the rows are null for that column.

Upvotes: 0

Related Questions