Click here to Skip to main content
15,889,834 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to use Exists on this sql statement ?

update m set m.rohsstatus=RHst.Name from #ManuFacture m

                         inner JOIN Parts.ROHS Rhh WITH(NOLOCK) ON Rhh.ZPartID=m.PartID
             inner JOIN Nop_AcceptedValuesOption RHst WITH(NOLOCK) on RHst.AcceptedValuesOptionID=Rhh.RoHSStatus AND RHst.AcceptedValuesID=911


i need to update table ManuFacture where part id exist on Parts.ROHS

so i need it as below

update m set m.rohsstatus=RHst.Name from #ManuFacture m
where exists(select 1 from Parts.ROHS)

so i need to replace statement above by using exists but i can't do

What I have tried:

update m set m.rohsstatus=RHst.Name	   from #ManuFacture m
						where exists(select 1 from

							 Parts.ROHS Rhh WITH(NOLOCK) 
				inner JOIN Nop_AcceptedValuesOption RHst WITH(NOLOCK) 
				on RHst.AcceptedValuesOptionID=Rhh.RoHSStatus AND RHst.AcceptedValuesID=911
				where m.partid=Rhh.zpartid )
Posted
Updated 18-Feb-21 1:12am
v2

1 solution

Don't specify a table name or alias for the columns you're updating.

You also can't refer to columns in a sub-query from the outer query. You need to join to the relevant tables instead.
SQL
UPDATE
    m
SET
    rohsstatus = RHst.Name
FROM
    #Manufacture m
    INNER JOIN Parts.ROHS Rhh ON Rhh.zpartid = m.partid
    INNER JOIN Nop_AcceptedValuesOption RHst ON RHst.AcceptedValuesOptionID = Rhh.RoHSStatus AND RHst.AcceptedValuesID = 911
;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900