SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Asamco BV - Alex
-- Create date: 19-10-2019
-- Description: returns a plus or minus 1, whether it's in or out transaction of a serial number tx, based on SNTransType in SerialTX
-- =============================================
CREATE FUNCTION _as_f_SignedSerialQty
(
-- Add the parameters for the function here
@SNTransType int
)
RETURNS int
AS
BEGIN
-- Declare the return variable here
DECLARE @signedValue int
-- Add the T-SQL statements to compute the return value here
SELECT @signedValue = case
WHEN @SNTransType /* btInv */ = 0 THEN -1
WHEN @SNTransType /* btCrn */ = 1 THEN 1
WHEN @SNTransType /* btGrv */ = 2 THEN 1
WHEN @SNTransType /* btRts */ = 3 THEN -1
WHEN @SNTransType /* btAdjIn */ = 4 THEN 1
WHEN @SNTransType /* btAdjOut */ = 5 THEN -1
WHEN @SNTransType /* btStockTake */ = 6 THEN 1
WHEN @SNTransType /* btSOInv */ = 7 THEN -1
WHEN @SNTransType /* btPOGrv */ = 8 THEN 1
WHEN @SNTransType /* btWareTrfFrom */ = 9 THEN -1
WHEN @SNTransType /* btWareTrfTo */ = 10 THEN 1
WHEN @SNTransType /* btMakeMain */ = 11 THEN 1
WHEN @SNTransType /* btBreakMain */ = 12 THEN -1
WHEN @SNTransType /* btMakeComponents */ = 13 THEN -1
WHEN @SNTransType /* btBreakComponents */ = 14 THEN 1
WHEN @SNTransType /* btUnknown */ = 15 THEN 1
WHEN @SNTransType /* btTrfFromJob */ = 16 THEN 1
WHEN @SNTransType /* btTrfToJob */ = 17 THEN -1
WHEN @SNTransType /* btJobInv */ = 18 THEN -1
WHEN @SNTransType /* btMakeStockMain */ = 19 THEN 1
WHEN @SNTransType /* btMakeStockComponents */ = 20 THEN -1
WHEN @SNTransType /* btRtsFromJob */ = 21 THEN -1
WHEN @SNTransType /* btPOSInv */ = 22 THEN -1
WHEN @SNTransType /* btPOSCrn */ = 23 THEN 1
WHEN @SNTransType /* IBT - out */ = 33 THEN -1
WHEN @SNTransType /* IBT - in */ = 34 THEN 1
WHEN @SNTransType /* inv journal - in */ = 35 THEN 1
WHEN @SNTransType /* inv journal - out */ = 36 THEN 1
ELSE 0 END
-- Return the result of the function
RETURN @signedValue
END