Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Msg 402, Level 16, State 1, Procedure trg_UsersPro

Author  Topic 

programer
Posting Yak Master

221 Posts

Posted - 2014-06-22 : 15:29:28
Declare @ByName nvarchar(500)
Declare @Note nvarchar(4000)

SET @ByName=(SELECT Username from inserted inner join aspnet_Users
on inserted.UserId=aspnet_Users.UserId)

--IF UPDATE(COLUMNS_UPDATED)
IF (COLUMNS_UPDATED()) > 0
SET @Note='User details updated: First name '+(SELECT (COLUMNS_UPDATED()) from deleted) --+'-->'(SELECT UserId from inserted)

INSERT INTO tbl_Audit (UserId, Type,Date,ByName,Note) VALUES ((SELECT UserId from inserted),'1',GETDATE(),@ByName,@Note)
END

Error:
Msg 402, Level 16, State 1, Procedure trg_UsersProfilesAudit, Line 19
The data types varchar and varbinary are incompatible in the add operator.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2014-06-22 : 17:12:03
[code]INSERT dbo.tbl_Audit
(
UserID,
Type,
Date,
ByName,
Note
)
SELECT i.UserID,
'1',
GETDATE(),
i.Username,
'User details updated: First name (old) ' + d.Firstname + ' (new) ' + i.FirstName
FROM deleted AS d
INNER JOIN inserted AS i ON i.UserId = d.UserId;[/code]


Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page
   

- Advertisement -