|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Thursday, March 12, 2009 9:06 AM
Points: 171,
Visits: 6
|
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Wednesday, May 01, 2013 8:12 AM
Points: 1,104,
Visits: 331
|
|
This is also the way I have done things. We have a form with 7 check boxes for days of the week, the user can check any combination and this can be stored neatly and efficiently as 1 tinyint range [0-127]. The bitwise queries to retrieve the data are also efficient and very useful once you have taken the time to understand the maths behind the operations. The alternative is 7 database fields and queries with lots of OR operators - a lot more work to product some ugly queries.
Regards, Andy Jones andyj93@hotmail.com
Regards, Andy Jones
|
|
|
|
|
SSCertifiable
       
Group: Moderators
Last Login: Thursday, May 09, 2013 12:38 PM
Points: 6,462,
Visits: 1,384
|
|
|
|
|
|
SSC-Dedicated
           
Group: Administrators
Last Login: Yesterday @ 1:47 PM
Points: 31,406,
Visits: 13,722
|
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Wednesday, May 14, 2008 12:28 PM
Points: 49,
Visits: 4
|
|
I've used all three methods, depending on the situation. I use packing bits most of the time when I need to "score" rows based on some criteria to determine a sort order, or ranking. This often takes the form of:
update my_table set score = case when criteria_1 = <somevalue> then 2^15 else 0 end + case when criteria_2 = <anothervalue> then 2^14 else 0 end
This works well for me when some criteria have a higher value, and so if one fact is true about a row, that causes it to score better than all rows that do not have that value set. Of course in this case, I generally don't need to pull the individual bits back out since I could instead just query the data, and I'm really just using the calculated field to sort the table.
Matthew Galbraith
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Wednesday, February 20, 2013 8:55 AM
Points: 283,
Visits: 9
|
|
Kudos for the originality and efficiency. However, very respectfully, from a design perspective, I do not share an enthusiasm for such schemes for the following reasons:
1. Like a couple other respondents, I think there are scalability issues. There is a practical limit to the number of possible responses for any given question.
2. I'll be interested in seeing your approach to querying, but to me it looks like you'll be using the '&' operator. Not everyone would agree that this is programmer-friendly.
3. I have an old-fashioned bias in favor of storing data in a manner, where possible, that looks like what's being modeled. A simple schema would have a table containing a row for each question on a survey, and another table containing a row for each user/response to each question; multiple responses (e.g., question 2: 'a', 'b', and 'd') would get multiple rows. The disadvantages in space would be compensated for by the ability to include textual responses such as comment fields.
These are just my own prejudices, and are certainly not being put forth as "better". Your method, in fact, is more sophisticated and rates a much higher "Gee whiz!" factor.
Edited by - Lee Dise on 06/27/2002 2:27:55 PM
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Thursday, March 12, 2009 9:06 AM
Points: 171,
Visits: 6
|
|
Thanks for the kind words and suggestions. I am not sure who gets more out of the articles in this format the reader or the author. When I sent my articles in I was totally caught of guard by the forum but it is really cool.
Scalability is a major drawback with this method and I should have noted that in the article. If I had more time on the project I probably would have tried to figure out where a good cut-off point is for this type of method.
It is one of those projects that is on my list of things to get back to. Of course, that list keeps growing and I rarely get a chance to get back to it.
Bruce Szabo, MCSE+I, MCDBA, MCSD
Bruce Szabo, MCSE+I, MCDBA, MCSD
|
|
|
|