Solved

Returning results from search page using SQL Server 2000

Posted on 2011-09-07
4
247 Views
Last Modified: 2012-05-12
Hi.  I am trying to figure out a way to return results to users searching for data in an Access 2010 frontend (created in Access 2003) that has a SQL Server 2000 backend.  The backend is a data warehouse that will eventually have lots of data.  Right now there are only about 4,000 master records and 40,000 detail records.

Users will be selecting materials from a dropdown and then I need to return SampleIDs that use the materials selected.

Below is a small sample of how the data looks.  The real tables have many more rows per SampleID and many materials.  But, like the sample data, there are 2 different material fields (used for different purposes in the database) that I need to look at in each row for the purposes of this search project.

MasterID is the key in the first table and DetailID is the key in the second table.  The two tables are related by MasterID.  

Here are two examples:  
1. A user selects materials AA and DD from the list (they can select up to 4 materials).   I need to return sampleID 6-123 as the only sampleid that uses those materials.

2. A user selects material WW from the list.  I need to return sampleIDs 4-234 and 6-123 since they both use WW.

I wrote SQL code to take all the materials in the normalized detail table and concatenate all the materials (possibly 2 per row but with many rows) and put all that data as one line per SampleID in a pre-processed table.

For example:
SampleID      MaterialsList
4-234            AA,XX,WW,QQ,DD,TT
6-123            EE,FF,AA,BB,WW,XX,QQ

Then I could do a “like” in the search but the program to create the data above takes a while to run from SQL Agent.  When I run it in the Query Analyzer, takes less than 40 seconds but from the SQL Server Agent with a stored procedure, it isn’t even finished after 5 minutes.  So the first problem using the SP to create stored data I can search from is that I would have to run this process on a regular basis and the data would never be current to the moment unless the process just ran.  The second problems is that using a ”like” operator means the process to return search results may be slow.  We will eventually be upgrading to a later version of SQL Server and a much faster server but, for now, this is what we have to work with.

Then I thought that there may be a way to get this logic to run without using pre-processed data.   I am working on that now.  I tried using a select with a subselect to get the materials but that won’t work because multiple materials are returned from the subselect.

I hope my explanation makes sense.  Does anyone have any suggestions?

Thanks,
Alexis
 Sample data
0
Comment
Question by:alexisbr
  • 3
4 Comments
 

Author Comment

by:alexisbr
ID: 36496795
Here's the subquery I wrote for this test data:
select sampleid, (select material1 from MaterialTestDetail b where b.masterid = a.masterid)
from MaterialTestMaster a

I get the error "subquery returned more than 1 value" since more than one material1 value exists.  If I could somehow do this select and be able to concatenate the multiple results, including the values in material2, into one line, that might work.  I would then have to compare the material(s) the user selected against this list and return the sampleid or multiple sampleids.

Thanks,
Alexis
0
 
LVL 21

Accepted Solution

by:
Jason Yousef, MS earned 500 total points
ID: 36498121
that will help you get more about concatenate string values.

http://www.simple-talk.com/sql/t-sql-programming/concatenating-row-values-in-transact-sql/

sorry don't have access to 2000 to help you with an actual query...
0
 

Author Comment

by:alexisbr
ID: 36509592
huslyer,
Thanks for the link.  I got pulled into a last minute project after I posted this question and have not had a chance to review it yet.  I should be able to get back to this today.

Alexis
0
 

Author Closing Comment

by:alexisbr
ID: 36525619
Thanks for the great links.  This should help resolve my questions.  I will post another question if I need more help.
Alexis
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Backing up an SQL Transaction Log 11 41
SQL Error in WHERE Clause 5 39
Permissions on Database 11 37
Can't connect to new installation of SQL Server 2016 6 29
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now