473,498 Members | 2,026 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

String matching precedence

An application filters records based on names found in them. For
example, looking through property buyer names, looking for banks and
relocation companies.

I have a table of names and patterns:

CREATE TABLE #Filters (Pattern varchar(100), IfWildCard int, Category
int)
INSERT #Filters SELECT 'Bank Of America', 0, 1
INSERT #Filters SELECT '% Bank %', 1, 2
INSERT #Filters SELECT 'Bank %', 1, 2
INSERT #Filters SELECT '% Bank', 1, 2
INSERT #Filters SELECT 'Credant Reloc%', 1, 3
INSERT #Filters SELECT '%Relocation%, 1, 3

The filtering matches the table of candidate names against the filters,
and returns Category, where the where clause or join is
(Candidate = Pattern AND IfWildCard = 0)
OR (Candidate LIKE Pattern AND IfWildCard = 1)

"Bank of America" matches an exact pattern, and also a wildcard
pattern, and the two different matches give different values for
Category. Is there a way to control which match takes precedence, or
is necessary to do it multiple times in the desired order, removing
those that hae already matched from consideration?

Thanks,
Jim Geissman

May 2 '06 #1
5 1751
Stu
Well, how would YOU determine precedence? Is an exact match better
than a wildcard match? Without more details, its difficult to give
advice.

Stu

May 2 '06 #2
I know the order of preference. Let's say that exact matches take
preference over wildcards, or alternatively they should be in ascending
order by the Category column.

My question is, given that I know it, how to ensure the matching is
done in that order, as opposed to randomly or according to the whims of
SQLS. I'm thinking that multiple passes may be required, but I would
like to avoid that on the assumption it would be quicker to do it all
at once.

For example, to do them in order by Category, I could outer join the
candidates to (SELECT * FROM #Filters WHERE Category=1) AS f1 ON ...
and also outer join to (same thing, Category=2) AS f2, and so forth.
Would those matches be attempted in the order the joins appear?

Thanks,
Jim

May 2 '06 #3
(ji**********@countrywide.com) writes:
An application filters records based on names found in them. For
example, looking through property buyer names, looking for banks and
relocation companies.

I have a table of names and patterns:

CREATE TABLE #Filters (Pattern varchar(100), IfWildCard int, Category
int)
INSERT #Filters SELECT 'Bank Of America', 0, 1
INSERT #Filters SELECT '% Bank %', 1, 2
INSERT #Filters SELECT 'Bank %', 1, 2
INSERT #Filters SELECT '% Bank', 1, 2
INSERT #Filters SELECT 'Credant Reloc%', 1, 3
INSERT #Filters SELECT '%Relocation%, 1, 3

The filtering matches the table of candidate names against the filters,
and returns Category, where the where clause or join is
(Candidate = Pattern AND IfWildCard = 0)
OR (Candidate LIKE Pattern AND IfWildCard = 1)

"Bank of America" matches an exact pattern, and also a wildcard
pattern, and the two different matches give different values for
Category. Is there a way to control which match takes precedence, or
is necessary to do it multiple times in the desired order, removing
those that hae already matched from consideration?


SELECT TOP 1 ...
FROM ...
WHERE ...
ORDER BY Category

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.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
May 2 '06 #4
Thanks, Erland. I have a whole table of Candidates, that may match one
or more filters, and I would like to filter them all at once. Does
your suggestion do that? I'm afraid my SQL is so limited that I don't
see how. I didn't mention this, but I have roughly 1,000 filters and
100 mil names. Of the names, maybe 10 mil match a filter, with maybe
1/4 of those matching more than one.

Thanks,
Jim

May 2 '06 #5
Now I think I see it -- select candidate, min(category)
from candidates join filters on ... group by candidate

Sorry to start a wild goose chase.

Thanks,
Jim

May 2 '06 #6

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

Similar topics

15
1786
by: Francois De Serres | last post by:
hiho, what's the clean way to translate the tuple (0x73, 0x70, 0x61, 0x6D) to the string 'spam'? TIA, Francois
21
2995
by: siliconwafer | last post by:
Hi, In case of following expression: c = a && --b; if a is 0,b is not evaluated and c directly becomes 0. Does this mean that && operator is given a higher precedence over '--'operator? as...
11
1530
by: Rupesh | last post by:
Hello all, See the code .... int i=-3,j=2,k=0,m; m=++i;&&++j||++k; printf ("%d %d %d %d",i,j,k,m); I executed this code on gcc. the o/p i had got is:- -2 3 0 1
19
78745
by: Paul | last post by:
hi, there, for example, char *mystr="##this is##a examp#le"; I want to replace all the "##" in mystr with "****". How can I do this? I checked all the string functions in C, but did not...
7
2647
by: Brian Mitchell | last post by:
Is there an easy way to pull a date/time stamp from a string? The DateTime stamp is located in different parts of each string and the DateTime stamp could be in different formats (mm/dd/yy or...
5
5731
by: olaufr | last post by:
Hi, I'd need to perform simple pattern matching within a string using a list of possible patterns. For example, I want to know if the substring starting at position n matches any of the string I...
5
2520
by: junky_fellow | last post by:
Hi, I have a very basic doubt about associativity and precedence of operators. I am not a computer science person and may find it quite weird. Consider an expression 4+5*2
9
3724
by: marko | last post by:
/* code start */ int a = 0; /* expected evaluation and excution order with precedence in mind /* False(3) , True(1), False(2) */ if ( (a=1) == 0 || 0 != 1 && (a =2) == 1) putchar('T');...
11
4803
by: tech | last post by:
Hi, I need a function to specify a match pattern including using wildcard characters as below to find chars in a std::string. The match pattern can contain the wildcard characters "*" and "?",...
0
6993
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...
0
7375
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...
0
5456
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,...
1
4899
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...
0
4584
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3088
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...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1411
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
650
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.