Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Get values for some columns in trigger

$
0
0

I have INSTEAD OF TRIGGER when insert into table. The reason is that I have to get the value for some columns from other tables, before insert (or i will have to update after insert)

example:

If EXISTS(SELECT * from dbo.someOtherTable t INNER JOIN inserted i ON t.id=i.id)
SET @col2=1
ELSE

SET @col2=0

and so on....

At the end i execute insert. It works.

But then I have problems with MERGE statements, where I have update beside insert:
The target 'dbo.myTable' of the MERGE statement has an INSTEAD OF trigger on some, but not all, of the actions specified in the MERGE statement

I can replace instead of trigger to normal trigger, but then I will have to update the row after insert was done.

I can also separate Merge to update and insert statement separately.

Enable trigger also for update, but since i don't need it at update it has no sense.

Any other solution?

br, Simon


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>