469,898 Members | 1,576 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,898 developers. It's quick & easy.

Counting columns that match input data

JJ
Is it possible to count the number of columns that match certain conditions
and return a single value?

For example in the database we have a record where:

Column 1 = Male
Column 2 = A
Column 3 = B
Column 4 = D
Column 5 = M

And the data to be used for the query is:

Column 1 = Male
Column 2 = D
Column 3 = B
Column 4 = Z
Column 5 = M

I would like to be able to return all records where Column 1 = Male and also
return how many columns (from Column 2 through 5) match the data input. In
this case the number would be 2 since Column 3 and Column 5 in the database
match the data used for the query. If no columns match the input data, the
number returned would be 0.

Does that make sense? Can anybody help me out with a sql statement that
will do this? It would be greatly appreciated.

Thanks!
May 4 '06 #1
1 1970
JJ
I figured out a way to do it. I can use a series of IF() functions and add
them together.

"JJ" <no*****@thank.you> wrote in message
news:44**********************@news.astraweb.com...
Is it possible to count the number of columns that match certain
conditions and return a single value?

For example in the database we have a record where:

Column 1 = Male
Column 2 = A
Column 3 = B
Column 4 = D
Column 5 = M

And the data to be used for the query is:

Column 1 = Male
Column 2 = D
Column 3 = B
Column 4 = Z
Column 5 = M

I would like to be able to return all records where Column 1 = Male and
also return how many columns (from Column 2 through 5) match the data
input. In this case the number would be 2 since Column 3 and Column 5 in
the database match the data used for the query. If no columns match the
input data, the number returned would be 0.

Does that make sense? Can anybody help me out with a sql statement that
will do this? It would be greatly appreciated.

Thanks!

May 4 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by SL_McManus | last post: by
5 posts views Thread by Axial | last post: by
5 posts views Thread by explode | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.