all groups > sql server programming > august 2004 >
You're in the

sql server programming

group:

Query returning best match


Re: Query returning best match Partha Mandayam
8/20/2004 2:19:11 PM
sql server programming: Please post ddl, show some sample data and your desired result.

Regards

Partha Mandayam
Software Consultant
Home page: http://partha.tripod.com


*** Sent via Developersdex http://www.developersdex.com ***
Re: Query returning best match Partha Mandayam
8/20/2004 3:17:29 PM
There is a basic flaw in your design
Can you organize data like this?

Table A:
ArticleHead Aritcle text
1 VCR
2 Recordable VCR
3 Stereo VCR
4 Super VHS
5 Audio
6 TV

Table B
Article
2 Philips DCR 1000
2 Sony TRV
2 JVC HRD


then we can easily match article=2 in table b with article=2 in table A.

In your case, how will you find rows in table B which match
articlehead in table a=1? how will you distinguish these from the
records for 1.1?

You have to have some logical relationship between the two tables.

Regards

Partha Mandayam
Software Consultant
Home page: http://partha.tripod.com


*** Sent via Developersdex http://www.developersdex.com ***
Query returning best match lasse
8/20/2004 10:35:40 PM
I have two tables, A and B. Table A consist of article headers, while table
B consist of article Numbers. Each article number`s first 2-5 digits is the
header number. After the header number there is 1 to 5 additional digits
giving the uniqe article number.

I want to be able to do a lookup towards the article header, giving me the
header equal to most digits in the article number. Please note that the
number of digits to remove from the article number is not constant.

Is this possible using Transact??

Thanks
Lasse

Re: Query returning best match Tamas Bojcan - bojci
8/20/2004 11:19:25 PM
Hi,

It's possible. If I don't misundertand your explanation then SUBSTRING(
article_number, 2, 3 ) gives back the header and you can do a SELECT on
tableA using that value.


[quoted text, click to view]

Re: Query returning best match lasse
8/20/2004 11:30:56 PM
I will try to be more precise:

Table A:
ArticleHead Aritcle text
1 VCR
1.1 Recordable VCR
1.2 Stereo VCR
1.3.4 Super VHS
2 Audio
3 TV

Table B
Article
1.1100 Philips DCR 1000
1.11001 Sony TRV
1.11 JVC HRD

All of these articles should be connected to header 1.1, so that I can group
my articles in line with the article head table. The idea is to find the
best match. The problem is that I will never know how many digits or
characters to cut of in table B to do a lookup on the header in article A. I
must simple have a way to remove one and one digit untill I get a match.

All help is vry much appreciated.

lasse


"Partha Mandayam" <mcp111@hotmail.com> skrev i melding
news:%23A3CXtvhEHA.1644@tk2msftngp13.phx.gbl...
[quoted text, click to view]

Re: Query returning best match lasse
8/21/2004 9:35:42 AM
The basic idea was to make a best match, first trying to find article head
from the article number, then reducing one digit / character at a time in
the article number from the right until we got a match in article head. This
way we should be able to always find a "best match".

lasse

"Partha Mandayam" <mcp111@hotmail.com> skrev i melding
news:OoKT8NwhEHA.556@tk2msftngp13.phx.gbl...
[quoted text, click to view]

Re: Query returning best match Partha Mandayam
8/21/2004 7:43:20 PM
In your case, how will you find rows in table B which match
[quoted text, click to view]


Regards

Partha Mandayam
Software Consultant
Home page: http://partha.tripod.com


*** Sent via Developersdex http://www.developersdex.com ***
AddThis Social Bookmark Button