473,404 Members | 2,114 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,404 software developers and data experts.

Update table using partial word match

Hi Alex (Kuznetsov) and All,

This is to follow up with my last post, "Link two tables using partial
word match".
How can I UPDATE table using partial word match?
How can I write a SQL statement to do so? (I am using MS-Access.)
The two tables and the expected result are listed below:

Thank you in advance!

- Grasshopper -

================================================== =====
TABLE: tblStreet_Value (Table to be undated)

Street Value2
--------------- ------
123 ABC Street
124 ABC Street
125 ABC Street
1 XYZ AVE
2 XYZ AVE
3 XYZ AVE
10 CBS Street
11 CBS Street
12 CBS Street
100 Apple Road
101 Apple Road
102 Apple Road
TABLE: TblWord_Number

Word Number Value
---- ------ -----
ABC 123 NY
ABC 125 CA
CBS 11 MA
CBS 12 TX
Result

Street Value2
--------------- ------
123 ABC Street NY
124 ABC Street
125 ABC Street CA
1 XYZ AVE
2 XYZ AVE
3 XYZ AVE
10 CBS Street
11 CBS Street MA
12 CBS Street TX
100 Apple Road
101 Apple Road
102 Apple Road

Jan 20 '07 #1
5 5669
Hi,
This might work...
update tblStreet_Value
set Value2 = TblWord_Number.Value2
from TblWord_Number
where patindex(TblWord_Number.Number+ ' ' + TblWord_Number.Word +
'%',Street) 0
SQL Learner wrote:
Hi Alex (Kuznetsov) and All,

This is to follow up with my last post, "Link two tables using partial
word match".
How can I UPDATE table using partial word match?
How can I write a SQL statement to do so? (I am using MS-Access.)
The two tables and the expected result are listed below:

Thank you in advance!

- Grasshopper -

================================================== =====
TABLE: tblStreet_Value (Table to be undated)

Street Value2
--------------- ------
123 ABC Street
124 ABC Street
125 ABC Street
1 XYZ AVE
2 XYZ AVE
3 XYZ AVE
10 CBS Street
11 CBS Street
12 CBS Street
100 Apple Road
101 Apple Road
102 Apple Road
TABLE: TblWord_Number

Word Number Value
---- ------ -----
ABC 123 NY
ABC 125 CA
CBS 11 MA
CBS 12 TX
Result

Street Value2
--------------- ------
123 ABC Street NY
124 ABC Street
125 ABC Street CA
1 XYZ AVE
2 XYZ AVE
3 XYZ AVE
10 CBS Street
11 CBS Street MA
12 CBS Street TX
100 Apple Road
101 Apple Road
102 Apple Road
Jan 22 '07 #2

SQL Learner wrote:
Hi Alex (Kuznetsov) and All,

This is to follow up with my last post, "Link two tables using partial
word match".
How can I UPDATE table using partial word match?
How can I write a SQL statement to do so? (I am using MS-Access.)
The two tables and the expected result are listed below:

Thank you in advance!

- Grasshopper -

================================================== =====
TABLE: tblStreet_Value (Table to be undated)

Street Value2
--------------- ------
123 ABC Street
124 ABC Street
125 ABC Street
1 XYZ AVE
2 XYZ AVE
3 XYZ AVE
10 CBS Street
11 CBS Street
12 CBS Street
100 Apple Road
101 Apple Road
102 Apple Road
TABLE: TblWord_Number

Word Number Value
---- ------ -----
ABC 123 NY
ABC 125 CA
CBS 11 MA
CBS 12 TX
Result

Street Value2
--------------- ------
123 ABC Street NY
124 ABC Street
125 ABC Street CA
1 XYZ AVE
2 XYZ AVE
3 XYZ AVE
10 CBS Street
11 CBS Street MA
12 CBS Street TX
100 Apple Road
101 Apple Road
102 Apple Road

Try something like this (untested, I don't have Access):

UPDATE tblStreet_Value SET VALUE2 =
(SELECT MIN(Value) FROM TblWord_Number WHERE Street LIKE '%'+Word+'%'
AND Street LIKE CAST(Number AS VARCHAR(50))+'%')

-----------------------
Alex Kuznetsov
http://sqlserver-tips.blogspot.com/
http://sqlserver-puzzles.blogspot.com/

Jan 22 '07 #3
Thanks again, Alex.

I am having problem put the SQL in Access. Could you tell me the logic
of the select statement?

(SELECT MIN(Value) FROM TblWord_Number WHERE Street LIKE '%'+Word+'%'
AND Street LIKE CAST(Number AS VARCHAR(50))+'%')

Why are we using Min(Value) and what does "CAST(Number AS
VARCHAR(50))+'%')" mean and do?

I got your partial matching SQL code as follow:

========================
SELECT t.*
FROM tblStreet AS t
WHERE (((Exists (SELECT 1 FROM tblWord w WHERE t.Street LIKE
'*'+Word+'*'))<>False));
========================

I seems a little different from your new one.

This seems like a difficult query. Please help.

- Grasshopper -

Jan 22 '07 #4

SQL Learner wrote:
Thanks again, Alex.

I am having problem put the SQL in Access. Could you tell me the logic
of the select statement?

(SELECT MIN(Value) FROM TblWord_Number WHERE Street LIKE '%'+Word+'%'
AND Street LIKE CAST(Number AS VARCHAR(50))+'%')

Why are we using Min(Value) and what does "CAST(Number AS
VARCHAR(50))+'%')" mean and do?

I got your partial matching SQL code as follow:

========================
SELECT t.*
FROM tblStreet AS t
WHERE (((Exists (SELECT 1 FROM tblWord w WHERE t.Street LIKE
'*'+Word+'*'))<>False));
========================

I seems a little different from your new one.

This seems like a difficult query. Please help.

- Grasshopper -
If Number column is numeric, I cannot concatenate '%' to it directly, I
need to convert is to character type first.
Because the subquery without MIN() can return more than one value and
blow up, I need to restrict it to one value. i could use TOP 1 instead
of MIN(). You might get better help an an Access newsgroup.

-----------------------
Alex Kuznetsov
http://sqlserver-tips.blogspot.com/
http://sqlserver-puzzles.blogspot.com/

Jan 22 '07 #5
Hi Alan,

Thank you again for your help. I just posted the same question in the
Access group 1 hour ago.

Let's assume in Access (or SQL Server), the text and number can be
concatenated. Could you change your current code for me based on that
assumption?

Also, I thought the old code

SELECT t.* FROM tblStreet t WHERE EXISTS(SELECT 1 FROM tblWord w WHERE
t.Street LIKE '%'+Word+'%')

can be used for the new one?

- Grasshopper -

Jan 22 '07 #6

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

Similar topics

0
by: Phil Powell | last post by:
The table already has a fulltext index and from there I can use the MySQL fulltext search query to get results as well as the relevancy score. The problem I have is that MySQL has a default...
17
by: kalamos | last post by:
This statement fails update ded_temp a set a.balance = (select sum(b.ln_amt) from ded_temp b where a.cust_no = b.cust_no and a.ded_type_cd = b.ded_type_cd and a.chk_no = b.chk_no group by...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
2
by: NigelMThomas | last post by:
I have an especially challenging problem. I know there are a few geniuses in this group so perhaps; you can advise me whether or not this can be done as an update query in Access. Thanks. I am...
0
by: Metal2You | last post by:
I'm working on an ASP.NET 2.0 application in Visual Studio 2005 that accesses a Sybase database back end. We're using Sybase SQL Anywhere 9.0.2.3228. I have installed and registered the Sybase...
117
by: phil-news-nospam | last post by:
Is there really any advantage to using DIV elements with float style properies, vs. the old method of TABLE and TR and TD? I'm finding that by using DIV, it still involves the same number of...
16
by: ARC | last post by:
Hello all, So I'm knee deep in this import utility program, and am coming up with all sorts of "gotcha's!". 1st off. On a "Find Duplicates Query", does anyone have a good solution for...
6
by: Zetten | last post by:
I have an AD search module which works as I want it to; searching for a matching forename and/or surname in the appropriate OU. I would like to extend it to be more flexible, so that instead of...
3
by: planethax | last post by:
I have multiple arrays that I need to insert/update database and I am not sure how to start, I think I need to use the "foreach" statement and also not sure whether or not to serialize and...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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,...

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.