Jump to content
  • 0

Need help with an IF THEN statement in a trigger action


DavidwDavis

Question

I'm working on a trigger action (part of it pictured below) using an IF THEN logic where lots of data are inserted into various tables when a comparison is true versus not being inserted when a comparison is false. It works great when the comparison is simple, such as 1 equals 1 versus 1 equals 2.  But what I want to compare is a student_id being inserted versus a student_id in a different table. The logic I need is: If the student_id being inserted in table A is not in table B then all of the insertions will occur. If the student_id being inserted in table A is already in table B then none of the insertions will occur.

My problem is figuring out how to create this field comparison between student_id in  what is being inserted and student_id in another table. This is what I have been trying and it doesn't work. I've also tried putting in joins but that hasn't worked either. I've tried not using TOP in each select but then I get an error message. I don't know where to go from here.

Thanks for any help!

David Davis

1734584101_exampletrigger.thumb.JPG.e8d721c4c5da81939ffb397eb7a0d86b.JPG

 

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

NiceDuck,

Thanks for the feedback, I appreciate the help!

I realize I only provided a small snippet to keep things focused so you weren't able to see the entire trigger, which is lengthy and has multiple record insert actions in it. I would have had to use lots of where conditions. Using one IF THEN statement actually kept the trigger simpler and easier to understand.

David Davis

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...