Count Across Columns

C

Craig

In a query,m I have selected four fields plus the id field from a table of
50.
Each of the records are marked with an X or not.


ID 2000 2002 2004 2006 Count ?
1 x x x 3
2 x x 2
3 x x 2
4 x x x x 4


How can I count the number of fields that are notnull accross the four
columns?
I am looking at 600,000 records

THanks
Craig
 
B

BillyRogers

SELECT
Table1.ID,
IIf([Field1] Is Not Null,1,0)+
IIf([Field2] Is Not Null,1,0)+
IIf([Field3] Is Not Null,1,0)+
IIf([Field4] Is Not Null,1,0) AS NumerofNonNullFields

FROM Table1;




--
Billy Rogers

Dallas,TX

Currently Using SQL Server 2000, Office 2000 and Office 2003
 
C

Craig

Thankyou

Just what i needed.

Craig


BillyRogers said:
SELECT
Table1.ID,
IIf([Field1] Is Not Null,1,0)+
IIf([Field2] Is Not Null,1,0)+
IIf([Field3] Is Not Null,1,0)+
IIf([Field4] Is Not Null,1,0) AS NumerofNonNullFields

FROM Table1;




--
Billy Rogers

Dallas,TX

Currently Using SQL Server 2000, Office 2000 and Office 2003


Craig said:
In a query,m I have selected four fields plus the id field from a table
of
50.
Each of the records are marked with an X or not.


ID 2000 2002 2004 2006 Count ?
1 x x x 3
2 x x 2
3 x x 2
4 x x x x 4


How can I count the number of fields that are notnull accross the four
columns?
I am looking at 600,000 records

THanks
Craig
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top