Hi all
I have a FOR INSERT trigger on one table that inserts data into another table.
If the application does an insert into the base table the trigger executes.
If I execute a manual SQL insert statement, data is inserted into the base table but nothing happens in the other table.
At first I tried a bulk insert and then a one record insert and it still didn't work.
The login that the app uses has db_datareader and db_datawriter permissions, I have sysadmin rights.
Here is the trigger code but the trigger does work just not when I insert data thru query analyser.
CREATE trigger dbo.INSERT_TAGCOST on dbo.TAG_TRANSACTION
FOR INSERT
AS
-- fetch transaction entries from tag_transaction to record costs against the tag in tag_cost
insert into tag_cost (cost_class_id, tag_trx_id, tag_no, cost_type, cost_value, cost_desc, action_user, action_date, user_updated, date_updated)
select t.cost_class_id, t.tag_trx_id, t.tag_no, tc.cost_type, t.trx_value, t.trx_desc, s.sys_user_id, i.date_updated, t.user_updated, getdate()
from inserted i, tag_cost_class tc, ips2dev.dbo.sys_user s, tag_transaction t
where t.tag_trx_id = i.tag_trx_id
and t.user_updated = s.sys_user_nt_id
and t.cost_class_id = tc.cost_class_id
and (t.trx_type_code in ('Create') or t.cost_class_id in (1, 2, 4))
and (t.tag_trx_id not in (select tag_trx_id from tag_cost where tag_trx_id is not null))
Here is the insert statement:
insert into tag_transaction (tag_no, trx_type_code, trx_value, application, trx_desc, date_updated, cost_class_id)
select tag_no, 'IPMLOG', 150, 'IPM', 'Nominal Cost', getdate(), 4)
from asset where tag_no = 'PC8000'
trx_value uses money and cost_class_id use int therefore no ''.
What could the cause for this be?
John
I have a FOR INSERT trigger on one table that inserts data into another table.
If the application does an insert into the base table the trigger executes.
If I execute a manual SQL insert statement, data is inserted into the base table but nothing happens in the other table.
At first I tried a bulk insert and then a one record insert and it still didn't work.
The login that the app uses has db_datareader and db_datawriter permissions, I have sysadmin rights.
Here is the trigger code but the trigger does work just not when I insert data thru query analyser.
CREATE trigger dbo.INSERT_TAGCOST on dbo.TAG_TRANSACTION
FOR INSERT
AS
-- fetch transaction entries from tag_transaction to record costs against the tag in tag_cost
insert into tag_cost (cost_class_id, tag_trx_id, tag_no, cost_type, cost_value, cost_desc, action_user, action_date, user_updated, date_updated)
select t.cost_class_id, t.tag_trx_id, t.tag_no, tc.cost_type, t.trx_value, t.trx_desc, s.sys_user_id, i.date_updated, t.user_updated, getdate()
from inserted i, tag_cost_class tc, ips2dev.dbo.sys_user s, tag_transaction t
where t.tag_trx_id = i.tag_trx_id
and t.user_updated = s.sys_user_nt_id
and t.cost_class_id = tc.cost_class_id
and (t.trx_type_code in ('Create') or t.cost_class_id in (1, 2, 4))
and (t.tag_trx_id not in (select tag_trx_id from tag_cost where tag_trx_id is not null))
Here is the insert statement:
insert into tag_transaction (tag_no, trx_type_code, trx_value, application, trx_desc, date_updated, cost_class_id)
select tag_no, 'IPMLOG', 150, 'IPM', 'Nominal Cost', getdate(), 4)
from asset where tag_no = 'PC8000'
trx_value uses money and cost_class_id use int therefore no ''.
What could the cause for this be?
John