Advertisement
Advertisement
| 06.17.2008 at 03:00PM PDT, ID: 23493422 |
|
[x]
Attachment Details
|
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: |
/****** Object: Trigger [scheme].[mihaddcost_ins] Script Date: 06/17/2008 22:25:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [scheme].[mihaddcost_ins]
ON [scheme].[opdetm]
AFTER INSERT
AS
--Trigger used to modify the driver field in opdetm with costs stored in stockm.
--The value entered depends on the currency of the customer.
--stockm.setup cost holds the sterling value
--stockm.shelf_life holds the euro value
INSERT INTO [scheme].[opdetm_cost]
SELECT i.order_no
, i.order_line_no
, CASE WHEN RTRIM(LTRIM(c.currency)) = 'EUR' AND s.shelf_life > 0
THEN s.shelf_life
WHEN RTRIM(LTRIM(c.currency)) = 'EUR' AND s.shelf_life = 0
THEN s.standard_cost
WHEN RTRIM(LTRIM(c.currency)) = '' AND s.setup_cost =0
THEN s.standard_cost
WHEN RTRIM(LTRIM(c.currency)) = '' AND s.setup_cost > 0
THEN s.setup_cost
ELSE 0
END
* CASE WHEN i.order_line_status ='B'
THEN i.order_qty
WHEN i.allocated_qty>0
THEN i.allocated_qty
WHEN i.despatched_qty>0
THEN i.despatched_qty
ELSE i.order_qty
END
, CASE RTRIM(LTRIM(c.currency))
WHEN 'EUR' THEN i.val/1.27
ELSE i.val END AS STGVAL
, o.date_entered
, i.line_type
, o.territory
FROM INSERTED i
JOIN [scheme].[opheadm] o
ON o.order_no = i.order_no
JOIN [scheme].[slcustm] c
ON c.customer = o.customer
LEFT JOIN [scheme].[stockm] s
ON s.[product] = i.product
AND s.[warehouse]= i.warehouse
|