sql 用于创建标量函数的SQL代码将输入变量
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql 用于创建标量函数的SQL代码将输入变量相关的知识,希望对你有一定的参考价值。
CREATE function GL.fn_Code_Descriptions (@segment1 varchar,@segment2 varchar,@segment3 varchar,@segment4 varchar,@segment5 varchar)
RETURNS varchar(50)
AS
BEGIN
return (SELECT
--(gcc.SEGMENT1 + '.' + gcc.SEGMENT2 + '.' + gcc.SEGMENT3 + '.' + gcc.SEGMENT4 + '.' + gcc.SEGMENT5) AS GL_Code,
(ffvt1.DESCRIPTION + '.' + ffvt2.DESCRIPTION + '.' + ffvt3.DESCRIPTION + '.' + ffvt4.DESCRIPTION + '.' + ffvt5.DESCRIPTION) AS GL_Description
FROM GL_CODE_COMBINATIONS gcc
LEFT OUTER JOIN FND.FND_ID_FLEX_SEGMENTS fifs1
ON fifs1.ID_FLEX_NUM = gcc.CHART_OF_ACCOUNTS_ID
AND fifs1.APPLICATION_ID = 101
AND fifs1.ID_FLEX_CODE = 'GL#'
AND fifs1.ENABLED_FLAG = 'Y'
AND fifs1.SEGMENT_NUM = 1
LEFT OUTER JOIN FND_FLEX_VALUES ffv1
ON ffv1.FLEX_VALUE_SET_ID = fifs1.FLEX_VALUE_SET_ID
AND ffv1.FLEX_VALUE = gcc.SEGMENT1
LEFT OUTER JOIN FND_FLEX_VALUES_TL ffvt1
ON ffv1.FLEX_VALUE_ID = ffvt1.FLEX_VALUE_ID
AND ffvt1.LANGUAGE = 'US'
LEFT OUTER JOIN FND.FND_ID_FLEX_SEGMENTS fifs2
ON fifs2.ID_FLEX_NUM = gcc.CHART_OF_ACCOUNTS_ID
AND fifs2.APPLICATION_ID = 101
AND fifs2.ID_FLEX_CODE = 'GL#'
AND fifs2.ENABLED_FLAG = 'Y'
AND fifs2.SEGMENT_NUM = 2
LEFT OUTER JOIN FND_FLEX_VALUES ffv2
ON ffv2.FLEX_VALUE_SET_ID = fifs2.FLEX_VALUE_SET_ID
AND ffv2.FLEX_VALUE = gcc.SEGMENT2
LEFT OUTER JOIN FND_FLEX_VALUES_TL ffvt2
ON ffv2.FLEX_VALUE_ID = ffvt2.FLEX_VALUE_ID
AND ffvt2.LANGUAGE = 'US'
LEFT OUTER JOIN FND.FND_ID_FLEX_SEGMENTS fifs3
ON fifs3.ID_FLEX_NUM = gcc.CHART_OF_ACCOUNTS_ID
AND fifs3.APPLICATION_ID = 101
AND fifs3.ID_FLEX_CODE = 'GL#'
AND fifs3.ENABLED_FLAG = 'Y'
AND fifs3.SEGMENT_NUM = 3
LEFT OUTER JOIN FND_FLEX_VALUES ffv3
ON ffv3.FLEX_VALUE_SET_ID = fifs3.FLEX_VALUE_SET_ID
AND ffv3.FLEX_VALUE = gcc.SEGMENT3
LEFT OUTER JOIN FND_FLEX_VALUES_TL ffvt3
ON ffv3.FLEX_VALUE_ID = ffvt3.FLEX_VALUE_ID
AND ffvt3.LANGUAGE = 'US'
LEFT OUTER JOIN FND.FND_ID_FLEX_SEGMENTS fifs4
ON fifs4.ID_FLEX_NUM = gcc.CHART_OF_ACCOUNTS_ID
AND fifs4.APPLICATION_ID = 101
AND fifs4.ID_FLEX_CODE = 'GL#'
AND fifs4.ENABLED_FLAG = 'Y'
AND fifs4.SEGMENT_NUM = 4
LEFT OUTER JOIN FND_FLEX_VALUES ffv4
ON ffv4.FLEX_VALUE_SET_ID = fifs4.FLEX_VALUE_SET_ID
AND ffv4.FLEX_VALUE = gcc.SEGMENT4
LEFT OUTER JOIN FND_FLEX_VALUES_TL ffvt4
ON ffv4.FLEX_VALUE_ID = ffvt4.FLEX_VALUE_ID
AND ffvt4.LANGUAGE = 'US'
LEFT OUTER JOIN FND.FND_ID_FLEX_SEGMENTS fifs5
ON fifs5.ID_FLEX_NUM = gcc.CHART_OF_ACCOUNTS_ID
AND fifs5.APPLICATION_ID = 101
AND fifs5.ID_FLEX_CODE = 'GL#'
AND fifs5.ENABLED_FLAG = 'Y'
AND fifs5.SEGMENT_NUM = 5
LEFT OUTER JOIN FND_FLEX_VALUES ffv5
ON ffv5.FLEX_VALUE_SET_ID = fifs5.FLEX_VALUE_SET_ID
AND ffv5.FLEX_VALUE = gcc.SEGMENT5
AND ffv5.PARENT_FLEX_VALUE_LOW = gcc.SEGMENT4
LEFT OUTER JOIN FND_FLEX_VALUES_TL ffvt5
ON ffv5.FLEX_VALUE_ID = ffvt5.FLEX_VALUE_ID
AND ffvt5.LANGUAGE = 'US'
WHERE gcc.SEGMENT1 = @segment1
AND gcc.SEGMENT2 = @segment2
AND gcc.SEGMENT3 = @segment3
AND gcc.SEGMENT4 = @segment4
AND gcc.SEGMENT5 = @segment5)
end
--SELECT * FROM FND_FLEX_VALUES ffv
--WHERE ffv.FLEX_VALUE_SET_ID = 1007694
--AND ffv.FLEX_VALUE = '110'
CREATE FUNCTION MTL.fn_Available_Plant(@InvID AS numeric, @Orgz as numeric)
RETURNS numeric
AS
BEGIN
DECLARE @Avail numeric
SELECT @Avail = SUM(moqd.TRANSACTION_QUANTITY)
FROM MTL_ONHAND_QUANTITIES_DETAIL moqd
LEFT OUTER JOIN MTL_SECONDARY_INVENTORIES msi
ON msi.ORGANIZATION_ID = moqd.ORGANIZATION_ID
AND msi.SECONDARY_INVENTORY_NAME = moqd.SUBINVENTORY_CODE
WHERE moqd.INVENTORY_ITEM_ID = @InvID
AND moqd.ORGANIZATION_ID = @Orgz
AND ((msi.AVAILABILITY_TYPE = 1
AND msi.INVENTORY_ATP_CODE = 1) OR moqd.SUBINVENTORY_CODE = 'SAMS')
AND (moqd.SUBINVENTORY_CODE <> 'SHIP4'
OR moqd.SUBINVENTORY_CODE NOT LIKE 'FG%'
OR moqd.SUBINVENTORY_CODE NOT LIKE 'STG%'
OR moqd.SUBINVENTORY_CODE <> 'SAMS')
GROUP BY moqd.INVENTORY_ITEM_ID
RETURN @Avail
end
以上是关于sql 用于创建标量函数的SQL代码将输入变量的主要内容,如果未能解决你的问题,请参考以下文章