0

I have two tables, one named issue and the other named activ in SQL Server 2008. I am deleting a column in issue, but before I do so, I want to find the corresponding column in activ, and update a field. I'm just not sure how to reference activ.

issue
iissueid, iactivid, ...

activ
iactivid, rtfnotes, ...

UPDATE activ 
    SET activ.rtfnotes = NULL   
FROM issue
    JOIN activ.iactivid = issue.iactivid
WHERE issue.iissueid = @tID

DELETE issue WHERE iissueid = @tID

Could someone point out where I am going wrong. I'm pretty sure I am almost there.

Tim
  • 2,731
  • 9
  • 35
  • 72
  • In your UPDATE you have `SET active.rtfnotes = NULL` where everywhere else its `activ`. That could be the problem unless it is just a typo here. – Evan Frisch May 21 '15 at 19:28
  • @Walker - It was just a typo here, which I fixed. Thank you for making me aware of it. – Tim May 21 '15 at 19:35
  • 2
    "JOIN activ.iactivid = issue.iactivid" is not valid syntax. You JOIN a table/view ON a condition. – Tab Alleman May 21 '15 at 19:55
  • possible duplicate of [SQL update from one Table to another based on a ID match](http://stackoverflow.com/questions/224732/sql-update-from-one-table-to-another-based-on-a-id-match) – Tab Alleman May 21 '15 at 19:57
  • @TabAlleman - That was it. Stupid mistake on my part. Thank you. – Tim May 21 '15 at 20:10

1 Answers1

0
UPDATE a
    SET a.rtfnotes = NULL   
FROM activ a
    JOIN issue i ON a.iactivid = i.iactivid AND i.iissueid = @tID

DELETE issue WHERE iissueid = @tID
Sherman
  • 853
  • 5
  • 16