Solved

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

Posted on 2009-05-03
2
241 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:chrismichalczuk
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 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:chrismichalczuk
ID: 31577358
hard to follow
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Select distinct 25 60
SQL Select Help with xml tags in a text field 9 28
query help 18 51
SQL Server 2008 R2 - Execution Plan 3 30
Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now