sql server - SQL Trigger Error Code -
i trying develop sql server trigger seems throwing off error me when update records have same values trigger keyword value, if 1 record matches value, not throwing off error.
error code:
in regards trigger developing snl, seems producing error: subquery returned more 1 value. not permitted when subquery follows =, !=, <, <= , >, >= or when subquery used expression. statement has been terminated.
trigger code:
use [testtrigger] go /****** object: trigger [dbo].[testtrigger] script date: 06/04/2015 08:29:34 ******/ set ansi_nulls on go set quoted_identifier on go alter trigger [dbo].[testtrigger] on [dbo].[sn_contact2] insert,update begin declare @idstatus varchar(254) declare @contactid varchar(36) declare @clienturl nvarchar(254) set @contactid = (select contact_contactid inserted) set @idstatus = (select contact_category inserted) set @clienturl = (select cust_1004 inserted) if @idstatus = 'client' begin update sn_contact2 set cust_id_status_change_date = getdate() cust_main_contact = 'x' , cust_id_status_change_date null , cust_1004 = @clienturl end end
any thoughts?
these fault lines.. when more 1 records updated/inserted through single query, error (as sub query returning more 1 value..).
set @contactid = (select contact_contactid inserted) set @idstatus = (select contact_category inserted) set @clienturl = (select cust_1004 inserted)
change update query single row update :
update sn_contact2 set cust_id_status_change_date = getdate() cust_main_contact = 'x' , cust_id_status_change_date null , cust_1004 --= @clienturl in ( select cust_1004 inserted contact_category = 'client' )
Comments
Post a Comment