Recent PostsRecent Posts Popular TopicsPopular Topics
 Home Search Members Calendar Who's On

 Storing Checkbox Responses as Integers Rate Topic Display Mode Topic Options
Author
 Message
 Posted Wednesday, June 26, 2002 12:00 AM
 SSC-Enthusiastic Group: General Forum Members Last Login: Thursday, March 12, 2009 9:06 AM Points: 171, Visits: 6
 Comments posted to this topic are about the content posted at http://www.sqlservercentral.com/columnists/bszabo/storingresponses.asp Bruce Szabo, MCSE+I, MCDBA, MCSD
Post #5071
 Posted Thursday, June 27, 2002 1:34 AM
 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 cancheck any combination and this can be stored neatly and efficiently as 1 tinyint range [0-127]. The bitwise queries to retrievethe data are also efficient and very useful once you have taken the time to understand the maths behind the operations. The alternativeis 7 database fields and queries with lots of OR operators - a lot more work to product some ugly queries.Regards,Andy Jonesandyj93@hotmail.com Regards,Andy Jones
Post #36406
 Posted Thursday, June 27, 2002 4:58 AM
 SSCertifiable Group: Moderators Last Login: Thursday, December 05, 2013 11:47 AM Points: 6,598, Visits: 1,521
 Interesting. What about when you have a pick list of a hundred or a thousand items? Not uncommon at all.The approach we've taken is store a code for each answer selected. If you pick 3 items, we store 3 rows in the answer table.Andyhttp://www.sqlservercentral.com/columnists/awarren/
Post #36407
 Posted Thursday, June 27, 2002 10:16 AM
 SSC-Dedicated Group: Administrators Last Login: Yesterday @ 5:42 PM Points: 32,275, Visits: 14,529
 I think it's a question of scale. If business rules dictate a small number that is unlikely to substantially grow, I like having storage in a few columns. However, if this is an open-ended solution, I prefer to use multiple rows. Makes querying easier.Steve Jonessteve@dkranch.net Follow me on Twitter: @way0utwestForum Etiquette: How to post data/code on a forum to get the best help
Post #36408
 Posted Thursday, June 27, 2002 11:06 AM
 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_tableset score = case when criteria_1 = then 2^15 else 0 end +case when criteria_2 = then 2^14 else 0 endThis 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
Post #36409
 Posted Thursday, June 27, 2002 2:27 PM
 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
Post #36410
 Posted Thursday, June 27, 2002 8:08 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
Post #36411

 Permissions