"Leif Neland" <leif (AT) neland (DOT) dk> writes:
Quote:
I have a trigger which copies the values and a timestamp to stock_audit.
But if src is not set in a query
update stock set in_stock=in_stock-1 where id=12345
src keeps its old value, which is misleading.
So I want to put a default value in src if it is not explicitly set in the
query.
Can this be done? |
In MSSQL, UPDATE triggers can use IF UPDATE(column) to check
whether the named column was explicitly updated. I suppose that
should work in a CASE expression too, e.g. CASE WHEN UPDATE(src)
THEN inserted.src ELSE 'default value' END.
I'm not sure whether UPDATE(column) in INSERT triggers returns
the correct value or just always TRUE. Although perhaps it does
not matter for your purposes.