473,651 Members | 3,004 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Input string -> table -> output string?

I have a nasty situation in SQL Server 7.0. I have a table, in which
one column contains a string-delimited list of IDs pointing to another
table, called "Ratings" (Ratings is small, containing less than ten
values, but is subject to change.) For example:

[ratingID/descr]
1/Bronze
2/Silver
3/Gold
4/Platinum

When I record rows in my table, they look something like this:

[uniqueid/ratingIDs/etc...]
1/2, 4/...
2/null/...
3/1, 2, 3/...

My dilemma is that I can't efficiently read rows in my table, match the
string of ratingIDs with the values in the Ratings table, and return
that in a reasonable fashion to my jsp. My current stored procedure
does the following:

1) Query my table with the specified criteria, returning ratingIDs as a
column
2) Split the tokens in ratingIDs into a table
3) Join this small table with the Ratings table
4) Use a CURSOR to iterate through the rows and append it to a string
5) Return the string.

My query then returns...
1/"Silver, Platinum"
2/""
3/"Bronze, Silver, Gold"

And is easy to output.

This is super SLOW! Queries on ~100 rows that took <1 sec now take 12
secs. Should I:

a) Create a junction table to store the IDs initially (I didn't think
this would be necessary because the Ratings table has so few values)
b) Create a stored procedure that does a "SELECT * FROM Ratings," put
the ratings in a hashtable/map, and match the values up in Java, since
Java is better for string manipulation?
c) Search for alternate SQL syntax, although I don't believe there is
anything useful for this problem pre-SQL Server 2005.

Thanks!
Adam

Jul 13 '06 #1
2 2041
ad*******@gmail .com wrote:
I have a nasty situation in SQL Server 7.0. I have a table, in which
one column contains a string-delimited list of IDs pointing to another
table, called "Ratings" (Ratings is small, containing less than ten
values, but is subject to change.) For example:

[ratingID/descr]
1/Bronze
2/Silver
3/Gold
4/Platinum

When I record rows in my table, they look something like this:

[uniqueid/ratingIDs/etc...]
1/2, 4/...
2/null/...
3/1, 2, 3/...

My dilemma is that I can't efficiently read rows in my table, match the
string of ratingIDs with the values in the Ratings table, and return
that in a reasonable fashion to my jsp. My current stored procedure
does the following:

1) Query my table with the specified criteria, returning ratingIDs as a
column
2) Split the tokens in ratingIDs into a table
3) Join this small table with the Ratings table
4) Use a CURSOR to iterate through the rows and append it to a string
5) Return the string.

My query then returns...
1/"Silver, Platinum"
2/""
3/"Bronze, Silver, Gold"

And is easy to output.

This is super SLOW! Queries on ~100 rows that took <1 sec now take 12
secs. Should I:

a) Create a junction table to store the IDs initially (I didn't think
this would be necessary because the Ratings table has so few values)
b) Create a stored procedure that does a "SELECT * FROM Ratings," put
the ratings in a hashtable/map, and match the values up in Java, since
Java is better for string manipulation?
c) Search for alternate SQL syntax, although I don't believe there is
anything useful for this problem pre-SQL Server 2005.

Thanks!
Adam
Both a) and d):

a) Create a junction table...
d) Remember always that delimited lists don't belong in the database.

:-)

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/m...S,SQL.90).aspx
--

Jul 13 '06 #2
(ad*******@gmai l.com) writes:
I have a nasty situation in SQL Server 7.0. I have a table, in which
one column contains a string-delimited list of IDs pointing to another
table, called "Ratings" (Ratings is small, containing less than ten
values, but is subject to change.) For example:
...
My dilemma is that I can't efficiently read rows in my table, match the
string of ratingIDs with the values in the Ratings table,
I believe you. That design is a complete disaster, for the very
reasons you mention. It cannot be handled effeciently in a relational
database. The proper design is to put the repeating group in a
sub-table.
1) Query my table with the specified criteria, returning ratingIDs as a
column
2) Split the tokens in ratingIDs into a table
3) Join this small table with the Ratings table
4) Use a CURSOR to iterate through the rows and append it to a string
5) Return the string.

My query then returns...
1/"Silver, Platinum"
2/""
3/"Bronze, Silver, Gold"

And is easy to output.
A better alternative, using the current table design, would be get
the select data into a temp table in this way:

INSERT #temp (uniqueid, ratingID)
SELECT uniqueid, ',' + replace(ratingI D, ' ', '') + ','
FROM tbl

Note that you add trailing and leading commas, and remove all spaces.
Then loop over Ratings, and say;

UPDATE #temp
SET ratings = replace(ratings , ',' + @rating + ',',
',' + @descr + ',')
But in the long run, a table redesign is what you need.

--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jul 13 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
9098
by: blrmaani | last post by:
Here is what I want: string s1 = "This is a list of string"; list<string> s2 = s1.some_method(); Now, I should be able to traverse list s2 and get each member ( which is of type 'string' ). I know that this can be achieved using strtok. But I was wondering
1
5782
by: Thilo-Alexander Ginkel | last post by:
Hello, I am currently trying to assign some string to a TEXT output parameter of a stored procedure. The basic structure of the stored procedure looks like this: -- 8< -- CREATE PROCEDURE owner.StoredProc (
3
2518
by: ethoemmes | last post by:
I have used the import class module from http://www.mvps.org/access/modules/mdl0057.htm. This reads my text file into a string called myString. I am trying to append this string into table tblTEMPVendors. The string is tab delimited. I am trying to use the code below to do this but I need some help - How do I loop through the string if this was a recordset I know i would use do while not rs.eof but I can't get the syntax for a string...
5
1358
by: Jazper | last post by:
hi can anybody explain that to me: i did the following: - 1. input of char 244 ("ô") into string - 2. convert to getbytes - 3. convert back to string char 244 changed to char 63 ("?") why??? what can i do the get the same string...?
3
6028
by: Rico | last post by:
If there are consecutive occurrences of characters from the given delimiter, String.Split() and Regex.Split() produce an empty string as the token that's between such consecutive occurrences. It sounds like making sense, but has anyone ever found this useful? Can this 'feature' be disabled? After having used StringTokenizer from the J-language that's not to be named, it's annoyed me for hours before I figured out that it was just a...
5
75175
by: Andrew Robinson | last post by:
Any easy answer what is wrong here? private List<string> BodyWords = new List<string>(); string word = "Andrew"; the following causes a compilation error:
1
2451
by: James Coleman | last post by:
I am using the TreeView control in ASP.NET 2.0 and like it. However, our sitebuilders aren't too pleased with the idea of the table that gets rendered. They are big into avoiding <table> tags when it comes to site build. So is there a way I could have the following html be rendered from the treeview control? <div class="rightNavHighlight"><a href="#">Ergonomics</a></div> <div class="rightNavHighlight"><a href="#">Environmental
4
1886
YarrOfDoom
by: YarrOfDoom | last post by:
Hi I'm trying to get my input from a RichTextBox into a string, but the tabs in my input are left away. Is this a limitation of string, or am I doing something wrong? I'm trying to do this like this: string = RichTextBox.text Yarr Of Doom
2
2970
by: since | last post by:
How do I get IE and Mozilla to show the right border for an input tag. for the following table Everything looks great until I add the doctype tag. I can get IE to work by adding the following. table.resizable td{ overflow: hidden; padding-right:6px. }
0
8357
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8277
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8803
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8465
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7298
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6158
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4144
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4285
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1910
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.