[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How do I update a table from a linked table in Ms sql 2000

Posted on 2009-05-03
2
Medium Priority
?
252 Views
Last Modified: 2012-05-06
My update code doesnt work.
Tblsite links to tbladdress
tempmarketing2 links on postcode to tbladdress

this works as a select statement but the update statement below fails

SELECT tblAddress.Address_PostZip AS Expr1, tblSite.Site_Name AS Expr2, TempMarketing2.siteid AS Expr3, tblSite.Site_ID AS Expr4,
       TempMarketing2.company AS Expr5, *
  FROM TempMarketing2
 INNER JOIN tblAddress ON tblAddress.Address_PostZip = TempMarketing2.epostcod AND TempMarketing2.epostcod = tblAddress.Address_PostZip
 INNER JOIN tblSite ON tblAddress.Address_ID = tblSite.Site_Address AND LEFT(TempMarketing2.Company,1) = LEFT(tblSite.SITE_NAME,1)
 WHERE (tblSite.Site_Active = 1)
 ORDER BY TempMarketing2.epostcod, TempMarketing2.company, tblSite.Site_Name
Update TempMarketing2 
set siteid=tblsite.site_id
from tblsite
INNER JOIN tblAddress ON tblAddress.Address_PostZip = TempMarketing2.epostcod AND TempMarketing2.epostcod = tblAddress.Address_PostZip 
INNER JOIN tblSite ON tblAddress.Address_ID = tblSite.Site_Address AND LEFT(TempMarketing2.Company,1) = LEFT(tblSite.SITE_NAME,1)
 WHERE (tblSite.Site_Active = 1)

Open in new window

0
Comment
Question by:Chris Michalczuk
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 750 total points
ID: 24290805
you must join the UPDATE also#:
Update tm
set siteid=ts.site_id
from TempMarketing2 tm
INNER JOIN tblAddress a 
  ON a.Address_PostZip = tm.epostcod 
 AND tm.epostcod = a.Address_PostZip 
INNER JOIN tblSite ts 
  ON a.Address_ID = ts.Site_Address 
 AND LEFT(tm.Company,1) = LEFT(ts.SITE_NAME,1)
 and ts.Site_Active = 1

Open in new window

0
 

Author Closing Comment

by:Chris Michalczuk
ID: 31577358
hard to follow
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question