Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Issue with updating using a join

Posted on 2014-12-04
5
Medium Priority
?
67 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 60

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 60

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 52

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 60

Accepted Solution

by:
HainKurt earned 2000 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
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.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

610 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