Skip to content
Loading
  • Patrick Rainer
    +1
    i dont know much about database but i noticed(your using same alias) i.ExecutionId = i.ExecutionId so replaced left side i with Executions
    1. inner join Executions on Executions.ExecutionId = i.ExecutionId
    Correct would be:
    1. inner join Executions on Executions.ExecutionId = i.ExecutionId   
    Right sorry, but that still does not work as expected because it tries to insert null, which should not happen in this case I would like to not insert anything ...
    +1
  • Patrick Rainer
    +1
    I use ms sql, so I tried:
     
    1. SELECT i.ParticipationId  
    2.           from inserted i  
    3.                    inner join Executions e on i.ExecutionId = e.ExecutionId  
    4.                    inner join Courses c on c.CourseId = e.CourseId  
    5.           where c.TestNeeded = 1  
    6.             AND c.TestNeeded is not null  
    But getting the error:
    Cannot insert the value NULL into column 'ParticipationId', table 'prdevstu_TrainingTracking02.patrick.rainer.Tests'; column does not allow nulls. INSERT fails. 
    +1
  • Sachin Singh
    +1
    Inserted table only contains the copy of values which are inserted in the table , in your case you perhaps not inserting ParticipationId as it is auto incremented or similar, so it is null , now when you are trying to insert null value into not nullable column causing the error.
    +1
  • Patrick Rainer
    +1
    @
    Sachin Singh
     
    You are right, but how can I tell sql to not to insert if the value is null?
     
    I mean in pseudo code:
     
    If value = true then
       Insert row
    else if value = false
       return
    end if 
    +1
  • Sachin Singh
    +1
    what is your full business requirement
    you have tables as course, Execution and Participation , in which table you are inserting data and want trigger to do its work??
    +1