473,394 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Partial matching

Hello

I have 2 tables:

table1

CODE | PRICE
1234 | 20
234 | 10


table2

CODE | PRICE
1234a |
1234b |
1234c |
234a |
234b |
234c |
234d |

WHat I need to do is, compare the string for CODE in table 1 against what
is found in table2. The relationship is always the same in that
table2.code is always what is found in table1 plus one more character. SO
I need to update table2 based on that so the result is:

1234a | 20
1234b | 20
1234c | 20
234a | 10
234b | 10
234c | 10
234d | 10

I'm kind of a n00b, but I need to use the MID function perhaps? Any help
greatly appreciated.
Mar 1 '07 #1
7 2531
On Mar 1, 5:34 pm, NOS...@comcast.net (Tony V) wrote:
Hello

I have 2 tables:

table1

CODE | PRICE
1234 | 20
234 | 10

table2

CODE | PRICE
1234a |
1234b |
1234c |
234a |
234b |
234c |
234d |

WHat I need to do is, compare the string for CODE in table 1 against what
is found in table2. The relationship is always the same in that
table2.code is always what is found in table1 plus one more character. SO
I need to update table2 based on that so the result is:

1234a | 20
1234b | 20
1234c | 20
234a | 10
234b | 10
234c | 10
234d | 10

I'm kind of a n00b, but I need to use the MID function perhaps? Any help
greatly appreciated.
If this is a *one-time* update then the following seems to work:

UPDATE Table1
INNER JOIN Table2 ON Table2.Code LIKE Table1.Code & "?"
SET Table2.Price = [Table1].[Price];

However, if this is an ongoing thing then fix the structure of Table2
by splitting off the last character, e.g.

CODE SUBCODE
1234 a
1234 b
234 a
Mar 1 '07 #2
On Mar 1, 5:34 pm, NOS...@comcast.net (Tony V) wrote:
Hello

I have 2 tables:

table1

CODE | PRICE
1234 | 20
234 | 10

table2

CODE | PRICE
1234a |
1234b |
1234c |
234a |
234b |
234c |
234d |

WHat I need to do is, compare the string for CODE in table 1 against what
is found in table2. The relationship is always the same in that
table2.code is always what is found in table1 plus one more character. SO
I need to update table2 based on that so the result is:

1234a | 20
1234b | 20
1234c | 20
234a | 10
234b | 10
234c | 10
234d | 10

I'm kind of a n00b, but I need to use the MID function perhaps? Any help
greatly appreciated.
This should work if both code fields are of a string type.

UPDATE Table1, table2 SET table2.Price = [table1].[price]
WHERE (((Left([table2].[code],Len([table1].[code])))=[table1].
[code]));
If Table1 is a number field

UPDATE Table1, table2 SET table2.Price = [table1].[price]
WHERE ((Left([table2].[code],Len(CStr([table1].[code])))=CStr([table1].
[code])));

Mar 1 '07 #3
Hi Tony,

Well, in Tsql (the sql for sql server) you can do this:

Select t1.* From Table1 t1 Inner Join Table2 t2
On t1.Code = Left(t2.Code, Len(t2.Code)-1)

But this is not supported in Jet Sql (sql for Access). One Alternative
would be to create an additional table which would link these two table
-- say Table3

Table3 would contain these fields: Code1, Cod2
Code1, Code2
1234 1234a
1234 1234b
1234 1234c
1234 1234d
234 234a
234 234b
234 234c
234 234d

Now the sql statement looks like this:
select t1.*, t2.Code From (Table1 t1 Inner Join Table3 t3 On t1.Code =
t3.Code1) Inner Join Table2 t2 On t3.Code2 = t2.Code

Jet sql does support this statement. It may be a little tedious, but it
is a workaround.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Mar 1 '07 #4
NO****@comcast.net (Tony V) wrote in
news:98*******************@216.196.97.136:
Hello

I have 2 tables:

table1

CODE | PRICE
1234 | 20
234 | 10


table2

CODE | PRICE
1234a |
1234b |
1234c |
234a |
234b |
234c |
234d |

WHat I need to do is, compare the string for CODE in table 1
against what is found in table2. The relationship is always
the same in that table2.code is always what is found in table1
plus one more character. SO I need to update table2 based on
that so the result is:

1234a | 20
1234b | 20
1234c | 20
234a | 10
234b | 10
234c | 10
234d | 10

I'm kind of a n00b, but I need to use the MID function
perhaps? Any help greatly appreciated.
You would be better off using the LIKE operator.

Practice this on a copy of the database to make sure you get it
working correctly
Create a new query. Add both tables. Double click on each of the
table 2 fields to move them into the lower panel of the query
builder.
Put this in the Criteria row for the code column:
Like [table1].[code] & "*"

the * says to match any character.

Change the query to an update query.
Put this in the Update To: row of the Price column:
[table1].[price]

Note: If you have 123a and 1234a and 12345a these will all match
123 from table 1. You will need to try something like
Like [table1].[code] & "[A-Z]*"

the [A-Z] says only match characters in the range from A to Z.
--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Mar 2 '07 #5
Rich P <rp*****@aol.comwrote in
news:45*********************@news.qwest.net:
Hi Tony,

Well, in Tsql (the sql for sql server) you can do this:

Select t1.* From Table1 t1 Inner Join Table2 t2
On t1.Code = Left(t2.Code, Len(t2.Code)-1)

But this is not supported in Jet Sql (sql for Access). One
Alternative would be to create an additional table which would
link these two table -- say Table3
Actually it is supported in Jet SQL. but you must enter it in the
SQL view of the query builder. And NEVER open the query in design
view, because the query builder will protest then delete the join.
--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Mar 2 '07 #6
Select t1.* From Table1 t1 Inner Join Table2 t2
On t1.Code = Left(t2.Code, Len(t2.Code)-1)
I tried this in the Query Sql view but it complained anyway. How can
you get it to run? I must be missing something, maybe some [ ] square
brackets?

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Mar 2 '07 #7
Rich P <rp*****@aol.comwrote in
news:45*********************@news.qwest.net:
Select t1.* From Table1 t1 Inner Join Table2 t2
On t1.Code = Left(t2.Code, Len(t2.Code)-1)
I tried this in the Query Sql view but it complained anyway.
How can you get it to run? I must be missing something, maybe
some [ ] square brackets?

Rich

*** Sent via Developersdex http://www.developersdex.com ***
I just pasted it into the SQL View of Access 2002 and adjusted the
table names. It ran fine..

What was Access complaining. Could you have a data type mismatch
between your code columns?
--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Mar 3 '07 #8

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

Similar topics

17
by: Paul MG | last post by:
Hi Template partial specialization always seems like a fairly straightforward concept - until I try to do it :). I am trying to implement the input sequence type (from Stroustrup section...
9
by: Fat Elvis | last post by:
I'd like to extend some of my Asp.net pages by using Partial Classes. Example ASP.Net Page: public partial class Admin_Customer : System.Web.UI.Page { protected void Page_Load(object sender,...
3
by: chungiemo | last post by:
Hi I have a project with access it has 2 non-related tables in access, which should have been related by ID, due to the poor data entry standards I am trying to match records from table 1 to...
1
by: chungiemo | last post by:
Hi thought I would do another thread as this one is a bit different from the previous problem I am looking for a solution to the relating problem Comparing 2 access databases with 2 tables,...
2
by: Peted | last post by:
Hi, im moving a project from vs2005 to vs 2008. is doing so i have come across a compiler error regarding partial classes that i dont understand if anyone can explain it to me please the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...

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.