Connecting Tech Pros Worldwide Help | Site Map

having trouble with joins

Newbie
 
Join Date: Aug 2009
Posts: 19
#1: Sep 24 '09
I can't get this code to run on SQL server without the following error

Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'JOIN'.

UPDATE [tblAcsChargeAmts]
JOIN [T Accessorials_Estimated]
ON [tblAcsChargeAmts].[Shipment Id] = [T Accessorials_Estimated].[Shipment Id]
AND [tblAcsChargeAmts].[Load Id] = [T Accessorials_Estimated].[Load Id]
AND [tblAcsChargeAmts].[Acs Code] = [T Accessorials_Estimated].[Acs Code])
SET [tblAcsChargeAmts].[Est AP Amt] = [T Accessorials_Estimated].[AP Est Acs Amt],
[tblAcsChargeAmts].[Est AR Amt] = [T Accessorials_Estimated].[AR Est Acs Amt]
WHERE [tblAcsChargeAmts].[Est AP Amt] = 0
OR [tblAcsChargeAmts].[Est AR Amt] = 0;
Delerna's Avatar
Expert
 
Join Date: Jan 2008
Location: Sydney
Posts: 785
#2: Sep 24 '09

re: having trouble with joins


Here is the example from SQL servers help documentation

Expand|Select|Wrap|Line Numbers
  1. UPDATE titleauthor
  2.    SET title_id = titles.title_id
  3.    FROM titles INNER JOIN titleauthor 
  4.       ON titles.title_id = titleauthor.title_id 
  5.       INNER JOIN authors
  6.       ON titleauthor.au_id = authors.au_id
  7.    WHERE titles.title = 'Net Etiquette'
  8.       AND au_lname = 'Locksley'
  9.  

you need to model your update query like that.

Just a hint....

There is a lot of help available in MSSQL's help (with examples) that answers questions like this. You access that help from "query analyser"....not from "Enterprise manager".
PS Im talking from the perspective of MSSQL Server 2000 here. It's probably different in later versions
Reply