How to make a trigger conditional
Posted on 2001-08-13
Hello SQL experts. I will be grateful for any help on this one.
I am trying to customise a package (Maximo) which uses MSSQL Server 7.
I haven't used SQL before, and I've had no training, so I'm struggling a bit.
I discovered "triggers" and have had some success using them.
The following code works OK to populate the field "author" when my user is inserting a new workorder record:
- - - - -
CREATE TRIGGER [labor_info_ins] ON [workorder]
SET author =
(SELECT name FROM labor
WHERE laborcode = changeby)
- - - - - - -
My question is:
How do I make it populate "author" only if "author" is null. In other words, if the user actually enters an author name I want to use that, but if they don't I want to populate it by accessing the labor table.
I hope it is OK that I have categorised this question as easy. I imagine it is probably simple for someone who knows what they are doing (unlike me). If you think I am being too miserly please say so and I will upgrade the points.