How can I count number of non-null fields and store it in another field of a table in SQL Server

I have a table (Table1) in SQL Server 2005 that has 15 character fields: Field1, Field2, ... Field15. I also have a numeric field, called Cnt, which holds the number of non-null fields on the record. Is there an easy way to update the Cnt using a query to count the number of non-null fields on the record, in a table with about 70,000 records?
dwoolley3Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JestersGrindCommented:
You could do something like this.

UPDATE Table1
SET cnt = CASE WHEN Field1 IS NOT NULL THEN 1 ELSE 0 END +
     CASE WHEN Field2 IS NOT NULL THEN 1 ELSE 0 END +
...
     CASE WHEN Field15 IS NOT NULL THEN 1 ELSE 0 END

Greg

0
lluddenCommented:
UPDATE table1 SET Cnt =
    CASE WHEN Field1 IS NULL THEN 0 ELSE 1 END +
    CASE WHEN Field2 IS NULL THEN 0 ELSE 1 END +
    CASE WHEN Field3 IS NULL THEN 0 ELSE 1 END +
    CASE WHEN Field4 IS NULL THEN 0 ELSE 1 END +
    CASE WHEN Field5 IS NULL THEN 0 ELSE 1 END +
    CASE WHEN Field6 IS NULL THEN 0 ELSE 1 END +
    CASE WHEN Field7 IS NULL THEN 0 ELSE 1 END
--Repeat for each field
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dwoolley3Author Commented:
Works perfectly. Thx!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.