Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 Database Design and Application Architecture
 Best way to store multiple selections

Author  Topic 

richardlaw
Yak Posting Veteran

68 Posts

Posted - 2011-02-20 : 17:28:37
Hi

In the past, I've been happy working with relationship tables where I store the ID of a value from another table. Simple. But what is the best way to store multiple selections - for example, the user selects all appropriate. In this case, I won't know how many (if at all), and what data type would I use?

Many thanks
Richard

Richard Law

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2011-02-20 : 21:34:57
That question makes little sense. I am not sure you will get answer. Why does datatype matter for what a user selects?



Poor planning on your part does not constitute an emergency on my part.
Go to Top of Page

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2011-03-03 : 00:03:03
I think the answer you are looking for is "store more than one row - one for each selection in whatever type you store a single selection"
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2011-03-03 : 09:40:28
I think you're looking for a junction table.

declare @questions table (
questionID int,
question varchar(200),
...
)

declare @answers table (
questionid int
answerid int,
answer varchar(200),
...
)

declare @question_answers (
@questionid int,
@answerid int,
@userid int
)


- Lumbago
My blog-> http://thefirstsql.com/2011/02/07/regular-expressions-advanced-string-matching-and-new-split-function-sql-server-2008-r2/
Go to Top of Page
   

- Advertisement -