Monday 14 May 2012

Trigger

ALTER TRIGGER [dbo].[lelnoSearch] ON [dbo].[tblProductPropertyValue]
FOR INSERT, update,delete
AS

    declare @lelno int;   
  
    ---check for lelno named property
    select @lelno=i.Value ,@name=pp.PropertyName,@productid=i.ProductId from inserted i
left join tblProduct as p
on i.ProductId=p.ProductId
left join tblProductProperty as pp
on i.PropertyId=pp.PropertyId
where pp.PropertyName='lelno';

--check if data exists for coming productid
select @check=id from tblSearch where tblsearch.ProductId=@productid


 if @lelno <>null or @lelno is not null begin
 print @lelno
    if @check is not NULL or @check <>NULL
    update tblSearch  set lElNo=@lelno where productId=@productid
    else
        insert into tblSearch
               (lElNo,productId)               
        values(@lelno,@productid);
end

No comments:

Post a Comment