Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdate record using instead of trigger in sql server
    primarykey
    data
    text
    <p>I have trigger in sql server 2005 which checks for duplicate record and then update the record.</p> <pre><code>USE [CheckeCon] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER TRIGGER [dbo].[tgUserRoleExistForUpdate] ON [dbo].[Sec_UserRoles] INSTEAD OF Update AS declare @UserRoleId int, @UserId int,@RoleId int, @FromDate datetime,@ToDate datetime,@CntlCreatedBy nvarchar,@CntlModifiedAt nvarchar,@CntlCurLockNo smallint; select @UserRoleId=i.UserRoleId from inserted i; select @UserId=i.UserId from inserted i; select @RoleId=i.RoleId from inserted i; select @FromDate=i.FromDate from inserted i; select @ToDate=i.ToDate from inserted i; select @CntlCreatedBy=i.CntlCreatedBy from inserted i; select @CntlModifiedAt=i.CntlModifiedAt from inserted i; select @CntlCurLockNo=i.CntlCurLockNo from inserted i; BEGIN -- BEGIN TRAN IF NOT EXISTS ( SELECT * FROM Sec_UserRoles SEUR JOIN inserted i ON SEUR.RoleId = i.RoleId AND SEUR.UserId = i.UserId Where i.FromDate BETWEEN SEUR.FromDate AND SEUR.ToDate ) Update Sec_UserRoles Set UserId = @UserId,RoleId = @RoleId,FromDate = @FromDate,ToDate = @ToDate, CntlCreatedBy = @CntlCreatedBy,CntlModifiedAt = @CntlModifiedAt,CntlCurLockNo = @CntlCurLockNo Where UserRoleId = @UserRoleId --Commit; Else RAISERROR('User Role Association Already Present',15,1); --ROLLBACK; End </code></pre> <p>But the problem is that it can not update record only raised error which i given in trigger. how can i update record using trigger?</p> <p>Thanks in advanced.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload