Hi there everyone!
I have a problem that I am finding is beyond my limmited experience in SQL programing. I want to write a trigger that will do the following.
I have Three tables T1, T2 and T3. The primary key in T1 links to T2 but T2 has a different primary key. T1 also links to T3 in the same manner. IE both are 1 to many relationships. When a new entry is made in T2 I need to check if there was data entered into a particular field (F1). The data will NOT be a particular value but it will be an *******. If there is data entered then I need to use the value in F1 to calculate a new values for T3 and insert them as a new record. T2 and T3 will have an at least one existing record for the primary key in T1 and I will have to select the newest of these values based on date. For T2 I will need to select the new one and the one previous to the new one and subtract the old one from the new one. This value , which could be nerative, will then be added to the current values in fields in T3 to create the vew vales for inserting. How can I do this???? I was thinking that maybe it could all be done in a trigger? or would a stored procedure be better? Can anyone help me work this stuff out??
Thanks in advance