Solved

Issue with updating using a join

Posted on 2014-12-04
5
58 Views
Last Modified: 2014-12-07
UPDATE DIST_CUSTOMER_PRODUCT_ADJUSTMENT D
Join Setup_Tissue_Prefix STP On D.TissuePrefixId = STP.TissuePrefixId
SET D.ADJUSTMENT_AMOUNT = 3.0,
D.Adjustment = 0.00
Where STP.TypePrefix In ('0336')
And D.CustomerID IN (SELECT Customer_Code_id from setup_customer_Code where customer_desc LIKE 'HCA %')


Error message:

Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'D'.
0
Comment
Question by:Sanjeet
  • 3
5 Comments
 
LVL 51

Expert Comment

by:HainKurt
ID: 40480951
maybe this

UPDATE DIST_CUSTOMER_PRODUCT_ADJUSTMENT
SET D.ADJUSTMENT_AMOUNT = 3.0, D.Adjustment = 0.00
from DIST_CUSTOMER_PRODUCT_ADJUSTMENT d Join Setup_Tissue_Prefix STP On D.TissuePrefixId = STP.TissuePrefixId
Where STP.TypePrefix In ('0336')
And D.CustomerID IN (SELECT Customer_Code_id from setup_customer_Code where customer_desc LIKE 'HCA %')
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 40480963
or better this

UPDATE DIST_CUSTOMER_PRODUCT_ADJUSTMENT
   SET D.ADJUSTMENT_AMOUNT = 3.0, D.Adjustment = 0.00
  FROM DIST_CUSTOMER_PRODUCT_ADJUSTMENT d 
       inner Join Setup_Tissue_Prefix STP On D.TissuePrefixId = STP.TissuePrefixId and STP.TypePrefix = '0336'
       inner join setup_customer_Code c on D.CustomerID=c.Customer_Code_id and customer_desc LIKE 'HCA %'

Open in new window

0
 

Author Comment

by:Sanjeet
ID: 40480967
Got this error message:

Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "D.ADJUSTMENT_AMOUNT" could not be bound.
0
 
LVL 45

Expert Comment

by:Vitor Montalvão
ID: 40480971
You can't JOIN directly to an updated table. Here's how you should do it:
UPDATE D
 SET D.ADJUSTMENT_AMOUNT = 3.0,
      D.Adjustment = 0.00
FROM DIST_CUSTOMER_PRODUCT_ADJUSTMENT D
INNER JOIN Setup_Tissue_Prefix STP On D.TissuePrefixId = STP.TissuePrefixId 
WHERE STP.TypePrefix In ('0336') 
    AND D.CustomerID IN (SELECT Customer_Code_id from setup_customer_Code where customer_desc LIKE 'HCA %')

Open in new window

0
 
LVL 51

Accepted Solution

by:
HainKurt earned 500 total points
ID: 40480974
try removing alias

UPDATE DIST_CUSTOMER_PRODUCT_ADJUSTMENT
   SET ADJUSTMENT_AMOUNT = 3.0, Adjustment = 0.00
  FROM DIST_CUSTOMER_PRODUCT_ADJUSTMENT d 
       inner Join Setup_Tissue_Prefix STP On D.TissuePrefixId = STP.TissuePrefixId and STP.TypePrefix = '0336'
       inner join setup_customer_Code c on D.CustomerID=c.Customer_Code_id and customer_desc LIKE 'HCA %'

Open in new window


or if qer above gives error. try this:

UPDATE d
   SET d.ADJUSTMENT_AMOUNT = 3.0, d.Adjustment = 0.00
  FROM DIST_CUSTOMER_PRODUCT_ADJUSTMENT d 
       inner Join Setup_Tissue_Prefix STP On D.TissuePrefixId = STP.TissuePrefixId and STP.TypePrefix = '0336'
       inner join setup_customer_Code c on D.CustomerID=c.Customer_Code_id and customer_desc LIKE 'HCA %'

Open in new window

0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Performance is the key factor for any successful data integration project, knowing the type of transformation that you’re using is the first step on optimizing the SSIS flow performance, by utilizing the correct transformation or the design alternat…
Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

747 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

12 Experts available now in Live!

Get 1:1 Help Now