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 5 1768
Well, how would YOU determine precedence? Is an exact match better
than a wildcard match? Without more details, its difficult to give
advice.
Stu
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
(ji**********@c ountrywide.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****@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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
|
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 opposed to what is mentioned in precedence table?
Also,
with comma operator.
consider,
|
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
|
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 find one.
|
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 dd/mm/yyyy, or hh:mm:ss
dd/mm...etc.)
Any ideas would be appreciated,
Thanks!!
| |
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 have a list, as
below:
sentence = "the color is $red"
patterns =
pos = sentence.find($)
|
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
|
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');
printf("%d", a);
/* code end */
2
|
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 "?",
where "*" matches zero or more consecutive occurrences of any
character and "?" matches a single occurrence of any character.
Does boost or some other library have this capability? If boost does
have this, do i need to include an entire
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |