I found a temporary solution
create trigger tr_orderTotalPrice on Orders for insert
as
Begin
select od.unitprice, od.Quantity,
Discount=CONVERT(int, Discount * 100),
TotalPruductPrice =round(CONVERT(money, Quantity * (1 - Discount *100) * Od.UnitPrice),2)
into #TotalPruductPrice
from orders o, [Order Details] od, inserted i
where i.orderID = o.orderID
and o.orderID = od.orderID
if (select sum(TotalPruductPrice) from #TotalPruductPrice) > 20000
BEGIN
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'AdventureWorks2012 Administrator',
@recipients = 'danw@Adventure-Works.com',
@body = 'Don''t forget to print a report for the sales force.',
@subject = 'Reminder';
END
End
but in this case I must had inserted values into Order Details table before I insert to Order table
but I can't of course because there is relationship between the two tables
so I have to use the following code to add values to order details table
ALTER TABLE "Order Details" NOCHECK CONSTRAINT ALL
go
INSERT "Order Details" VALUES('','','','','')
No comments:
Post a Comment