Search code examples
sqlsql-serversql-updatesubquery

sql update - access to the current row


I would like update the column [ACIdent] from the table [Values]. With the subquery i try to get an ID from the same table.

On the point ??? i try to access to the column [PathName] of the respective row of the update script. But this solution doesn't work.

How can i do this? Many thanks in advance!

Update [Values]
Set ACIdent = 

(Select  b.valueIdent  From Values as b Where b.SampleIdent = 0 and b.PathName = ???Values.PathName)
  
Where ValueIdent= 614

Solution

  • Restructure your query a bit so you can alias the table.

    
    Update v
    Set ACIdent = 
    
    (Select  b.valueIdent  From Values as b Where b.SampleIdent = 0 and b.PathName = v.PathName)
    
    From [Values] v
    Where v.ValueIdent= 614