All pastes #56295 Raw Edit

Untitled

public text v1 · immutable
#56295 ·published 2006-05-16 19:02 UTC
rendered paste body
DECLARE @qtyavailable	bigint,
		@qtyship 		int,
		@qtybo 			int 

SELECT @qtyavailable = CASE	WHEN producttypeid = 1 			THEN qtysemimanufactured
							WHEN porducttypeid IN (2,3,4,5)	THEN qtyfinished END
FROM product_info 
WHERE productid = @productid

-- calculate ship quantity and backorder quantity from stock available vs qty sold
IF @qtyavailable > @quantity
	SELECT @qtyship = @quantity
ELSE
	SELECT @qtybo = @quantity - @qtyavailable 

-- add the product item
INSERT INTO salesitem_info (salesid, productid, quantity, price, qtyship, qtybackorder)
VALUES (@salesid, @productid, @quantity, @price, @qtyship, @qtybo)