Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count number of fields populated from query

Status
Not open for further replies.

toyt78

Technical User
Apr 5, 2005
125
US
Anyway to find out how many fields are populated in a query on my Access 2000 database?

In the below I need to create a query to give me a count of 4 because 4 fields are populated:
Code:
TableOne:
Id    firstName   LastName   City        State
1     John        Jones      San Diego


This one would be a count of 3:
Code:
TableOne:
Id    firstName   LastName   City        State
1     John                   San Diego

Please advise?
Code:
select * from TableOne where LastName = "Jones";

 
Something like this (I assumed Id is never null)?
select *, 1+IIf([firstName] Is Null,0,1)+IIf([LastName] Is Null,0,1)+IIf([City] Is Null,0,1)+IIf([State] Is Null,0,1) AS CountOfFields
from TableOne
where LastName = "Jones";

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
what about something like
Code:
select *,count(*) as count from Tableone 
group by firstname
having lastname="Jones"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top