473,698 Members | 2,058 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL matching two multiple valued strings

Oat
I am a little stomped and wandering if someone might have an idea how
to go about doing this.

following on from this guide
http://www.4guysfromrolla.com/webtech/031004-1.shtml on matching a
comma-delimited string, I would like to expand on this and match two
comma-delimited string in a sproc.

In my database, table A have a city field containing a comma delimited
string ie 'sydney, new york, chicago'. I am passing a similar
comma-delimited string to a sproc and returning matcheing id.

so, we have table A:
id/city
1/sydney, new york, chicago
2/new york, san antonio
3/beijing, sydney
4/london,beijing

passing string 'sydney, new york'

need to return: id 1,2,3 (1,2 match new york and 1,3 matching sydney)

any ideas?
Jul 20 '05 #1
1 4554
On 10 Aug 2004 10:51:01 -0700, Oat wrote:
I am a little stomped and wandering if someone might have an idea how
to go about doing this.

following on from this guide
http://www.4guysfromrolla.com/webtech/031004-1.shtml on matching a
comma-delimited string, I would like to expand on this and match two
comma-delimited string in a sproc. In my database, table A have a city field containing a comma delimited
string ie 'sydney, new york, chicago'. I am passing a similar
comma-delimited string to a sproc and returning matcheing id.

so, we have table A:
id/city
1/sydney, new york, chicago
2/new york, san antonio
3/beijing, sydney
4/london,beijing

passing string 'sydney, new york'

need to return: id 1,2,3 (1,2 match new york and 1,3 matching sydney)

any ideas?


First, define the dbo.Split(@lst, @splitOn) as they do in that article.

Next, define a second UDF:

create FUNCTION match( @s1 varchar(1000), @s2 varchar(1000) )
returns int
as
begin
declare @r int
select @r = count(*) from
(select value from dbo.Split(@s1,' ,')) V1,
(select value from dbo.Split(@s2,' ,')) V2
where V1.value = V2.value
return(@r)
end
GO

Now you can do

SELECT A.ID FROM A
WHERE dbo.match(A.cit y, 'sydney, new york') > 0

This won't be fast on large datasets. Normalization is a much better
technique.
Jul 20 '05 #2

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

Similar topics

9
3209
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # Matching string patterns # # Sometimes you want to know if a string is of # particular pattern. Let's say in your website # you have converted all images files from gif # format to png format. Now you need to change the # html code to use the .png files. So, essentially
5
2350
by: Jamie Jackson | last post by:
Two fairly basic questions: I need to supply a method with an array of strings, which will eventually be used to pattern match against another array of strings. 1. Is there a good way to span multiple lines when creating an array from a list of strings? (I want the most readable list I can get.) // The following doesn't seem to work urlExclusions = newArray(
0
2741
by: Tom Warren | last post by:
I found a c program called similcmp on the net and converted it to vba if anybody wants it. I'll post the technical research on it if there is any call for it. It looks like it could be a useful tool for breaking ties when a phonic call returns a bunch of possibilities. Also, I'm looking for someone that has a zip code file with alternate city names (the PO assigns whatever name is convenient to them), email me if you got something. ...
10
9554
by: javuchi | last post by:
I'm searching for a library which makes aproximative string matching, for example, searching in a dictionary the word "motorcycle", but returns similar strings like "motorcicle". Is there such a library?
8
1678
by: EP | last post by:
Hi, I'm a bit green in this area and wonder to what extent there may be some existing Python tools (or if I have to scratch my head real hard for an appropriate algorithm... ) I'd hate to build an inferior solution to that someone has painstakingly built before me. I have some files which may have had the same origin, but some may have had some cruft added to the front, and some may have had some cruft added to the back; thus they...
7
2424
by: Captain Dondo | last post by:
I'm working on a terminal emulator for an embedded system. The key requirements are small size, code clarity, maintainability, and portability. We have machines that regularly see a service life of 30 years so it's not impossible that this code will be around that long. I'm trying to use termcap info to map incoming strings to display actions. In other words, I have an array that holds termcap info:
1
1598
by: gwigg | last post by:
Hi, I am trying to match multiple strings per line from a file and extract them into an array. Apparently the first match is assigned $1, how do I know what the last match is ie $last?? I would like to set up a for loop to enter these values into an array: psuedo code below to extract all html tag per line in the file master, array is mastertags: while (<$master>) { $_=~/(<.*?>)/g; for (my $i=1; $i <= last value; $i++)...
13
1591
by: lenygold via DBMonster.com | last post by:
I found this problem on ORACLE board. 2 input TABLES: Items Id ItemName 1 Phone 2 Table 3 Lamp 4 TV 5 Stereo
3
4974
by: simple simon | last post by:
How would I insert into multiple related tables using a table valued parameter? Is there any way to do this without using a WHILE loop? I know how to insert from a table valued parameter into one table: INSERT INTO dbo.Table SELECT * FROM @TVP But what do I do when I want to insert all of someone's information into multiple tables, and have those records related to each other by foreign keys? For example, I want to insert their address...
0
8603
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
9027
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8895
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
8861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7725
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
6518
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
4369
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...
2
2329
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.