sql server 2008 - Trigger update and handle null values -


i have trigger takes old values orginal tabel , put these values in 1 cell on table except date , user, when updates occurs, orginal table has attributes null when raw inserted (updatedate , updateuser), when raw updated 2 attributes update current date , user did update, trigger should 2 parameters when null should inserted values , when not null should new values,however trigger's syntax correct result incorrect

alter trigger [dbo].[ordersupdate] on [dbo].[orders] after update declare @updatedate datetime, @updateuser uniqueidentifier set @updatedate=(select updatedate deleted) set @updateuser=(select updateuser deleted) if @updatedate null begin set @updatedate=(select updatedate inserted) end else set @updatedate=(select updatedate deleted) if @updateuser null begin set @updateuser=(select updateuser inserted) end else set @updateuser=(select updateuser deleted) insert updaterows select 'orders', id,@updatedate,@updateuser, convert(nvarchar,invoiceid,1)+'_'+ convert(nvarchar,orderid,1)+'_'+ mattername+'_'+ convert(nvarchar,printid,1)+'_'+ ordername+'_'+ convert(nvarchar,lenght,1)+'_'+ convert(nvarchar,wide,1)+'_'+ convert(nvarchar,quantity,1)+'_'+  convert(nvarchar,enterdate,101)+'_'+  convert(nvarchar,enddate,101) deleted 

thanks hlgem

first, never ever write sql server trigger set values of scalar parameter inserted or deleted. these tables can contain multiple rows. trigger must account that. – hlgem


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -