dbTalk Databases Forums  

Re: [Fwd: Reverse pattern matching]

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Re: [Fwd: Reverse pattern matching] in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Hugo Kornelis
 
Posts: n/a

Default Re: [Fwd: Reverse pattern matching] - 05-18-2005 , 04:01 AM






On Tue, 17 May 2005 17:26:44 -0700, Gary Greenberg wrote:

Quote:
I encountered an unusual problem and wonder if anyone had some similar
experience. I have a table T where the column contains text values with
wild cards and a query contain exact value. For example
------------------------
| A | B |
------------------------
|AB% | 1 |
|X% | 2 |
|XY% | 3 |
|% | 4 |
------------------------

I'd like to make a query "select B from T where A like 'XYZ'"
I need to get a result sorted by maximum matching. For the liset case it
should be:
3
2
4

Any help will be greatly appreciated.
Hi Gary,

Try this one:

SELECT B
FROM YourTable
WHERE 'XYZ' LIKE A
ORDER BY LEN(A) DESC

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.