Let me see if I can explain my situation clearly.
I have a table with the columns:
answer_id, question_id, member_id, answer
- answer_id is the primary key for the table.
- question_id relates to another table with questions for a user. The
table holds the question and the possible choices in a varchar field
separated by a delimiter.
- member_id is self-explanatory
- answer is a varchar field of all the choices the user selected,
separated by a delimiter.
Here is my problem.
I am trying to search all members that have answered, say, question_id
= 2 where they selected 'brown' as one of their choices.
i can do this if they selected ONLY that item, but not multiple items.
The problem is this portion
answer in
(select valu from dbo.iter_intlis t.....
I need this to be something like....
function_to_ret urn_all_separat ed_answers(answ er) in
(select valu from dbo.iter_intlis t
The current way, it is only returning members that have an answer
'Brown', not 'Brown, Blue' in their answer field. Make any sense? So,
what I need to do is separate the list of answers and say :
select member_id from profile_answers where
ANY ANSWER in function_to_spl it(answer) MATCHES ANY OF THESE (select
valu from dbo.iter_intlis t...
It seems I might have to join or something, I am just a little lost
right now.
Here is my proc.
ALTER procedure search_detailed _get_ids
@question_id as integer,
@answers as varchar(8000),
@member_ids ntext
as
declare @v as varchar(8000)
--get the delimited string of all possible answers
set @v = (select bind_data from profiles_questi ons where question_id =
@question_id)
--prepare it for the function only accepting 1 char
set @v = replace(@v, '||', '|')
--gimme all members that match
select member_id from profiles_answer s where question_id = @question_id
and answer in
(select valu from dbo.iter_intlis t_to_table(@v, '|') where listpos in
(select valu from dbo.iter_intlis t_to_table(@ans wers, ',')))
and member_id in (select valu from dbo.iter_intlis t_to_table
(@member_ids, ','))
return
go
I have a table with the columns:
answer_id, question_id, member_id, answer
- answer_id is the primary key for the table.
- question_id relates to another table with questions for a user. The
table holds the question and the possible choices in a varchar field
separated by a delimiter.
- member_id is self-explanatory
- answer is a varchar field of all the choices the user selected,
separated by a delimiter.
Here is my problem.
I am trying to search all members that have answered, say, question_id
= 2 where they selected 'brown' as one of their choices.
i can do this if they selected ONLY that item, but not multiple items.
The problem is this portion
answer in
(select valu from dbo.iter_intlis t.....
I need this to be something like....
function_to_ret urn_all_separat ed_answers(answ er) in
(select valu from dbo.iter_intlis t
The current way, it is only returning members that have an answer
'Brown', not 'Brown, Blue' in their answer field. Make any sense? So,
what I need to do is separate the list of answers and say :
select member_id from profile_answers where
ANY ANSWER in function_to_spl it(answer) MATCHES ANY OF THESE (select
valu from dbo.iter_intlis t...
It seems I might have to join or something, I am just a little lost
right now.
Here is my proc.
ALTER procedure search_detailed _get_ids
@question_id as integer,
@answers as varchar(8000),
@member_ids ntext
as
declare @v as varchar(8000)
--get the delimited string of all possible answers
set @v = (select bind_data from profiles_questi ons where question_id =
@question_id)
--prepare it for the function only accepting 1 char
set @v = replace(@v, '||', '|')
--gimme all members that match
select member_id from profiles_answer s where question_id = @question_id
and answer in
(select valu from dbo.iter_intlis t_to_table(@v, '|') where listpos in
(select valu from dbo.iter_intlis t_to_table(@ans wers, ',')))
and member_id in (select valu from dbo.iter_intlis t_to_table
(@member_ids, ','))
return
go
Comment