1

I have a table (MYTABLE) in ms access 2003 with the following columns: table name, columnname and count I would like to read through the table and dynamically create an SQL statement for each table and column, run the SQL to get the count and update the 'count' column in the table.

Eg

My table has

Tablename columnname count
PATIENT.  AGE.          0

Generate SQL select Count(*) from PATIENT WHERE AGE IS NOT NULL

Update 'count' column in my table with the vaL of count

0

2 Answers 2

1

You can use the DCount Function in an UPDATE query.

UPDATE MYTABLE
SET [count] =
    DCount('*', [Tablename], '[' & columnname & '] Is Not Null');

That UPDATE statement examines each row in MYTABLE, gives DCount() the values stored in the Tablename and columnname fields, and stores the number returned from DCount in a field named count in the same row.

Sign up to request clarification or add additional context in comments.

2 Comments

I got an error with this.how do I iterate through MYTABLE and paras the value for table and columnar to DCount?
I revised the answer to explain how that UPDATE statement does iterate through the rows contained in MYTABLE. What was the error message you received?
0
Update tablename
set count=(select Count(*) from PATIENT WHERE AGE IS NOT NULL)
where table_name=PATIENT 

1 Comment

I assume you meant to say Update My table?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.