i try to write a trigger after insert ,checks my values if exists return me a default value or random one else insert users value in table.
alter trigger [dbo].[changevalues]
on [dbo].[products]
after insert
as
begin
declare @productname nvarchar(20),@prodcutprice money
select productname=@productname ,price=@prodcutprice
from inserted
if exists ( select * from products
where productname like @productname and price=@prodcutprice)
begin
insert products
values('fast',100)
end
else
begin
insert products
values(@productname,@prodcutprice)
end
end
i expect that the code returns me ('fast',100) but it return null in table
Aucun commentaire:
Enregistrer un commentaire