I am at a loss for how to write an insert for my situation. There are two tables involved:
SubstanceAbuse (OrderId, AssessmentID)
TempAsst(AssessmentID)
The insert has to do this:
For each TempAsst.AssessmentID, insert a record into SubstanceAbuse (3, AssessmentID) if there is not already a record in SubstanceAbuse with that AssessmentID and a value of 3 in the OrderID column.
Thanks!
Maybe something like:
insert into substanceAbuse (orderId, assessmentId)
select distinct
3,
assessmentId
from tempAsst a
where not exists
( select 0 from substanceAbuse b
where a.assessmentId = b.assessmentId
)
No comments:
Post a Comment