Showing posts with label explain. Show all posts
Showing posts with label explain. Show all posts

Tuesday, March 20, 2012

Comparing a column list split to a table.

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_intlist....

I need this to be something like...

function_to_return_all_separated_answers(answer) in
(select valu from dbo.iter_intlist

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_split(answer) MATCHES ANY OF THESE (select
valu from dbo.iter_intlist...

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_questions 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_answers where question_id = @.question_id
and answer in
(select valu from dbo.iter_intlist_to_table(@.v, '|') where listpos in

(select valu from dbo.iter_intlist_to_table(@.answers, ',')))
and member_id in (select valu from dbo.iter_intlist_to_table
(@.member_ids, ','))

return
gotwdo (johnj@.tampawebdevelopment.com) writes:
> 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.

Redo the table design, and move answer to a subtable:

CREATE TABLE answers (answer_id int NOT NULL,
answer varchar(10) NOT NULL,
CONSTRAINT pk_answers PRIMARY KEY (answer_id, answer)

Do the same for the answers to the questions.

If you are really stuck with the design, use temp tables in the
procedure. But note that with the design above it is not possible to
answer Brown more than once to a question - which presumably is a
good thing.

Working with comma-separated lists is really painful in SQL, because
relation algebra - in which SQL does take its foundation - assumes
that values are atomic, and yours aren't.

I can not really write a query for you with these tables, since I
couldn't make out whether Brown had to be a correct answer, or if
you just wanted any one who had answered Brown.

And, oh, the usual advice apply:

o CREATE TABLE statements for the tables involved.
o INSERT statements with sample data.
o The desired result given the sample.

That increases your does for a tested solution in reposnse.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||> o CREATE TABLE statements for the tables involved.
> o INSERT statements with sample data.
> o The desired result given the sample.
> That increases your does for a tested solution in reposnse.

I am stuck with the design of the tables. I can probably do some
looping to achieve what I need but I wanted to avoid loops at all costs
because of the performance.

Below is some table and data code. Basically, if you run the procedure
first provided, it will work if someone answers only ONE of the
possible choices (question_id = 1) BUT, if someone answers multiple
items, it will fail. I need it to split the list of answers and split
the list of possible choices and see if *ANY* match at all. Does that
make sense? I appreciate all help.

CREATE TABLE [dbo].[profiles_answers] (
[answer_id] [int] IDENTITY (1, 1) NOT NULL ,
[question_id] [int] NOT NULL ,
[member_id] [int] NOT NULL ,
[answer] [varchar] (7000) NOT NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[profiles_questions] (
[question_id] [int] IDENTITY (1, 1) NOT NULL ,
[group_id] [int] NOT NULL ,
[display_label] [varchar] (50) NOT NULL ,
[field_type_id] [int] NOT NULL ,
[bind_data] [varchar] (7000) NOT NULL ,
[display_order] [int] NOT NULL ,
[status] [int] NOT NULL
) ON [PRIMARY]
GO
INSERT INTO [dbo].[profiles_questions]
(group_id, display_label, field_type_id, bind_data, display_order,
status)
VALUES
(1, 'Interests', 1, 'Computers||Outdoors', 1, 1)
INSERT INTO [dbo].[profiles_questions]
(group_id, display_label, field_type_id, bind_data, display_order,
status)
VALUES
(1, 'Hair Color', 1, 'Brown||Black||Blonde', 1, 1)

INSERT INTO [dbo].[profiles_answers]
(question_id, member_id, answer)
VALUES
(2, 1, 'Brown')

INSERT INTO [dbo].[profiles_answers]
(question_id, member_id, answer)
VALUES
(1, 1, 'Computers, Outdoors')|||twdo (johnj@.tampawebdevelopment.com) writes:
> I am stuck with the design of the tables. I can probably do some
> looping to achieve what I need but I wanted to avoid loops at all costs
> because of the performance.

If you feel that you cannot change that design, don't even consider
performance. Perfomance is not achievable with that design.

> Below is some table and data code. Basically, if you run the procedure
> first provided, it will work if someone answers only ONE of the
> possible choices (question_id = 1) BUT, if someone answers multiple
> items, it will fail. I need it to split the list of answers and split
> the list of possible choices and see if *ANY* match at all. Does that
> make sense? I appreciate all help.

Thanks for the tables and insert data. But it would help a lot if you
gave different examples of input parameters, and what result you expect.
You refer to your procedure, but it cannot even run on the test data,
since it uses iter_intlist_to_table, and the answers are character...

Anyway, I don't really like guessing, since I may be wasting my time
on the wrong guess.

One hint is that instead of IN, use EXISTS instead. That's a more
powerful operator, with fewer gotchas, and often better performance.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp

Thursday, March 8, 2012

Compare based on table values.

Hi

Below is a table with sample data to explain what I want to achieve.

trackID member marker
allele1
--- -- ----------------
----------------
4734 4577 01-D8S1179 13.5
4734 4577 02-D21S11 12.6
4734 4577 03-D7S820 2.0
4734 4577 04-CSF1PO 3.0
4734 4577 06-TH01 4.0
4734 4577 07-D13S317 5.0
4734 4577 08-D16S539 9.0
4734 4577 11-vWA 6.0
4734 4577 12-TPOX 7.0
4734 4577 13-D18S51 1.0

4734 4578 01-D8S1179 13.0
4734 4578 02-D21S11 12.6
4734 4578 03-D7S820 2.0
4734 4578 04-CSF1PO 4.0
4734 4578 06-TH01 3.0
4734 4578 07-D13S317 5.0
4734 4578 08-D16S539 9.0
4734 4578 11-vWA 7.0
4734 4578 12-TPOX 6.0
4734 4578 13-D18S51 1.0

Okay I am trying to compare allele1 values for differences for two or
three different member having the same trackID. The list of markers
would always be same for all members belonging to a particular
trackID.

So in the above sample data. The trackID is same which is 4734. There
are two members 4577 and 4578. The markers are same for each members
but the corresponding allele1 values are different.

I want to compare these two and state whether they are same or not. I
would like to do this on a form containing subforms.

Feel free to ask for clarification.

Thank you.Rex wrote:

Quote:

Originally Posted by

Below is a table with sample data to explain what I want to achieve.
>
trackID member marker
allele1
--- -- ----------------
----------------
4734 4577 01-D8S1179 13.5
4734 4577 02-D21S11 12.6
4734 4577 03-D7S820 2.0
4734 4577 04-CSF1PO 3.0
4734 4577 06-TH01 4.0
4734 4577 07-D13S317 5.0
4734 4577 08-D16S539 9.0
4734 4577 11-vWA 6.0
4734 4577 12-TPOX 7.0
4734 4577 13-D18S51 1.0
>
4734 4578 01-D8S1179 13.0
4734 4578 02-D21S11 12.6
4734 4578 03-D7S820 2.0
4734 4578 04-CSF1PO 4.0
4734 4578 06-TH01 3.0
4734 4578 07-D13S317 5.0
4734 4578 08-D16S539 9.0
4734 4578 11-vWA 7.0
4734 4578 12-TPOX 6.0
4734 4578 13-D18S51 1.0
>
Okay I am trying to compare allele1 values for differences for two or
three different member having the same trackID. The list of markers
would always be same for all members belonging to a particular
trackID.
>
So in the above sample data. The trackID is same which is 4734. There
are two members 4577 and 4578. The markers are same for each members
but the corresponding allele1 values are different.


*scratches head* Oh, you mean that member 4577 has markers with values
(01-D8S1179, 02-D21S11, etc.) and member 4578 also has markers with
values (01-D8S1179, 02-D21S11, etc.).

Quote:

Originally Posted by

I want to compare these two and state whether they are same or not.


select t1.trackID,
t1.member t1_member,
t2.member t2_member,
t1.marker,
t1.allele1 t1_allele1,
t2.allele1 t2_allele1
from the_table t1
join the_table t2 on t1.trackID = t2.trackID
and t1.member < t2.member
and t1.marker = t2.marker
and t1.allele1 <t2.allele1

This does not check for members missing one or more markers. You can
do that as follows:

select t1.trackID,
t1.member t1_member,
t2.member t2_member,
t1.marker
from the_table t1
join the_table t2 on t1.trackID = t2.trackID
and t1.member <t2.member
where t1.marker not in (
select marker
from the_table t3
where t3.trackID = t2.trackID
and t3.member = t2.member
)

Quote:

Originally Posted by

I would like to do this on a form containing subforms.


Whut? Is this an Access thing? (Crystal Reports, my preferred
reporting layer, has reports containing subreports.)|||Rex (rakeshv01@.gmail.com) writes:

Quote:

Originally Posted by

Below is a table with sample data to explain what I want to achieve.
>
trackID member marker
allele1
--- -- ----------------
----------------
4734 4577 01-D8S1179 13.5
4734 4577 02-D21S11 12.6
4734 4577 03-D7S820 2.0
4734 4577 04-CSF1PO 3.0
4734 4577 06-TH01 4.0
4734 4577 07-D13S317 5.0
4734 4577 08-D16S539 9.0
4734 4577 11-vWA 6.0
4734 4577 12-TPOX 7.0
4734 4577 13-D18S51 1.0
>
4734 4578 01-D8S1179 13.0
4734 4578 02-D21S11 12.6
4734 4578 03-D7S820 2.0
4734 4578 04-CSF1PO 4.0
4734 4578 06-TH01 3.0
4734 4578 07-D13S317 5.0
4734 4578 08-D16S539 9.0
4734 4578 11-vWA 7.0
4734 4578 12-TPOX 6.0
4734 4578 13-D18S51 1.0
>
Okay I am trying to compare allele1 values for differences for two or
three different member having the same trackID. The list of markers
would always be same for all members belonging to a particular
trackID.
>
So in the above sample data. The trackID is same which is 4734. There
are two members 4577 and 4578. The markers are same for each members
but the corresponding allele1 values are different.
>
I want to compare these two and state whether they are same or not. I
would like to do this on a form containing subforms.


Don't really know where the form or the subform comes into the
picture. This is a group for a database engine. :-)

SELECT CASE WHEN EXISTS (SELECT 1
FROM tbl
WHERE member IN (@.member1, @.member2, @.member3)
AND trackID = @.trackID
GROUP BY marker
HAVING MIN(allelel) < MAX(allellel)
THEN 'There are difference'
ELSE 'All allellel are equal'
END

This is a bit of a guess, since it's not clear how you want the data.
For the future, a tip is that if you post:

o CREATE TABLE statement for your table.
o INSERT statements with sample data.
o The desired result given the sample.

Your odds for getting a tested query in respose are quite good.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

Wednesday, March 7, 2012

Compact Tools Download Problem

When I try and download Sqlce30setupen.msi from the msdn site, I keep getting the install for the mobile tools. Can someone explain why this is happening. I am new to SQL compact and I am trying to go through the tutorial http://msdn2.microsoft.com/en-us/library/bb226707.aspx. This tutorial says the download should be for SQL Compact setup.

Thanks

Ryan

All downloads for SQL Compact Edition are available from http://www.microsoft.com/sql/editions/compact/downloads.mspx|||

Hi Ryan,

Are you having the same problem as me? When I download the setup file from the SQL Compact downloads url provided, it doesn't install the Compac Server Tools but tries to install "Microsoft SQL Server 2005 Mobile SP1 [ENU] Server Tools". I'm trying to install on Windows Server 2003. Interestingly if I run the same file on XP Pro it successfully installs the Compact Server Tools. I just added a new thread about this problem.

Regards,

Greg

Compact Tools Download Problem

When I try and download Sqlce30setupen.msi from the msdn site, I keep getting the install for the mobile tools. Can someone explain why this is happening. I am new to SQL compact and I am trying to go through the tutorial http://msdn2.microsoft.com/en-us/library/bb226707.aspx. This tutorial says the download should be for SQL Compact setup.

Thanks

Ryan

All downloads for SQL Compact Edition are available from http://www.microsoft.com/sql/editions/compact/downloads.mspx|||

Hi Ryan,

Are you having the same problem as me? When I download the setup file from the SQL Compact downloads url provided, it doesn't install the Compac Server Tools but tries to install "Microsoft SQL Server 2005 Mobile SP1 [ENU] Server Tools". I'm trying to install on Windows Server 2003. Interestingly if I run the same file on XP Pro it successfully installs the Compact Server Tools. I just added a new thread about this problem.

Regards,

Greg

Sunday, February 19, 2012

Committed Memory

I recently did some performance testing and one of the
counters I monitored was Committed memory. Can someone
explain what this means. Is it the amount SQL Server can
access?
Also when AWE is enabled the memory used in Task manager
goes to whatever the limit is for SQL Server. Is that
because it is reserved for SQL Server processes.
Thanks for any advice.
JamieWhen you use AWE memory with SQL Server, SQL statically maps all of the
memory at startup (unlike nonAWE memory which is dynamic). If you want to
reserve less memory for SQL and leave more memory for other apps, use the
"sp_configure max server memory" option. Books on Line has a good
description under "Managing AWE Memory".
Brian Goldstein
SQL Server Product Group
--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm.
"Jamie Downs" <jamie@.and.co.uk> wrote in message
news:09b801c33fb5$93e73720$a101280a@.phx.gbl...
> I recently did some performance testing and one of the
> counters I monitored was Committed memory. Can someone
> explain what this means. Is it the amount SQL Server can
> access?
> Also when AWE is enabled the memory used in Task manager
> goes to whatever the limit is for SQL Server. Is that
> because it is reserved for SQL Server processes.
> Thanks for any advice.
> Jamie

Thursday, February 16, 2012

Comments in field titles.

Is there a way to place a comment into a feild title, like Excel? I have
reports that have comments that explain how the results were derived.Here was my solution. We created a hyperlink to a subreport and placed it in
the footer. " Further explaination to the test criteria may be found by
clicking HERE (on the web report)." That would take the user to a subreport
with all the definitions and leave a 'hint' trail on the printout or in
Excel.
"Candyman" wrote:
> Is there a way to place a comment into a feild title, like Excel? I have
> reports that have comments that explain how the results were derived.