Here's the updated stored procedure with the requested changes:

CREATE PROCEDURE [dbo].[InvoiceExpenseInsertUpdate4]
@DomainID INT,
@InvoiceUIDList VARCHAR(MAX),
@ExpenseMetricSkuValueTable ExpenseMetricSkuValueTable READONLY,
@LoginID INT,
@LoginEmail NVARCHAR(200),
@UserID VARCHAR(50),
@LoginName NVARCHAR(200),
@AppVersion VARCHAR(15) = 'not passed'
/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* Logic \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
Create a PX Expense according the given Allocation method among :
--0 -> Even Split at P1 level
--1 -> Gross Sales (GSR)
--2 -> Retail Sales
--3 -> Manual, Data is saved as P1 level with values provided by .Net
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/
AS
BEGIN
SET NOCOUNT ON;

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
Helpers
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/
DECLARE @ModifiedBy VARCHAR(200) = @LoginEmail -- :)
-- DECLARE @AllocationMethodEven INT = 0
-- DECLARE @AllocationMethodGSR INT = 1
-- DECLARE @AllocationMethodManual INT = 3

DROP TABLE IF EXISTS #InvoiceExpense;
CREATE TABLE #InvoiceExpense(
RowNo INT IDENTITY(1,1) -- will be used to manage insert split
, InvoiceExpenseID INT
, AllocationMethod TINYINT
, Interval INT NULL
, SkuID2 INT
, Date DATE
, MetricID INT
, Value DECIMAL(18,5)
);

INSERT #InvoiceExpense(
InvoiceExpenseID
, AllocationMethod
, Interval
, SkuID2
, Date
, MetricID
, Value
)
SELECT DISTINCT
e.InvoiceExpenseID
, e.AllocationMethod
, e.Interval
, p1.SkuID2
, e.Date
, e.MetricID
, e.Value
FROM
@ExpenseMetricSkuValueTable e
JOIN LP\_Sku p1 ON e.SkuMemberID = p1.MemberID
WHERE
p1.DomainID = @DomainID
AND e.InvoiceUID IN (SELECT value FROM string\_split(@InvoiceUIDList, ','));

DROP TABLE IF EXISTS #InvoiceExpenseSku;
CREATE TABLE #InvoiceExpenseSku(
RowNo INT
, InvoiceExpenseID INT
, SkuID2 INT
, MetricID INT
, [Date] DATE
, Value DECIMAL(18,5)
);

INSERT #InvoiceExpenseSku
SELECT
e.RowNo
, e.InvoiceExpenseID
, et.P1SkuID2
, e.MetricID
, e.Date
, et.P1Value
FROM
#InvoiceExpense e
JOIN @ExpenseMetricSkuValueTable et ON
e.InvoiceExpenseID = et.InvoiceExpenseID
AND e.MetricID = et.MetricID
AND e.Date = et.Date
AND e.AllocationMethod = et.AllocationMethod
JOIN LP\_Sku px ON
px.MemberID = et.SkuMemberID
AND px.SkuID2 = e.SkuID2;

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
Merge to physical tables
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/
DROP TABLE IF EXISTS #ChangeLog;
CREATE TABLE #ChangeLog (
ChangeType VARCHAR(10)
,
다음은 요청된 변경 사항이 포함된 업데이트된 저장 프로시저입니다:

CREATE PROCEDURE [dbo].[InvoiceExpenseInsertUpdate4]
@DomainID INT,
@InvoiceUIDList VARCHAR(MAX),
ExpenseMetricSkuValueTable ExpenseMetricSkuValueTable READONLY,
@LoginID INT,
@로그인이메일 NVARCHAR(200),
@UserID VARCHAR(50),
@로그인이름 NVARCHAR(200),
앱 버전 VARCHAR(15) = '통과되지 않음'
/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* Logic \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
중에서 주어진 할당 방법에 따라 PX 비용을 생성합니다:
--0 -> P1 수준에서 균등 분할
-1 -> 총 판매액(GSR)
--2 -> 소매 판매
-3 -> 수동, 데이터는 .Net에서 제공한 값으로 P1 수준으로 저장됩니다.
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/
AS
BEGIN
SET NOCOUNT ON;

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
Helpers
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/
DECLARE @ModifiedBy VARCHAR(200) = @로그인이메일 -- :)
-- DECLARE @AllocationMethodEven INT = 0
-- DECLARE @AllocationMethodGSR INT = 1
-- DECLARE @AllocationMethodManual INT = 3

DROP TABLE IF EXISTS #InvoiceExpense;
CREATE TABLE #InvoiceExpense(
RowNo INT IDENTITY(1,1) -- 삽입 분할을 관리하는 데 사용됩니다.
, InvoiceExpenseID INT
, AllocationMethod TINYINT
, Interval INT NULL
, SkuID2 INT
, Date DATE
, MetricID INT
, Value DECIMAL(18,5)
);

INSERT #InvoiceExpense(
InvoiceExpenseID
, AllocationMethod
, Interval
, SkuID2
, Date
, MetricID
, Value
)
고유 선택
e.InvoiceExpenseID
, e.AllocationMethod
, e.Interval
, p1.SkuID2
, e.Date
, e.MetricID
, e.Value
FROM
@ExpenseMetricSkuValueTable e
JOIN LP\_Sku p1 ON e.SkuMemberID = p1.MemberID
WHERE
p1.DomainID = @DomainID
AND e.InvoiceUID IN (SELECT value FROM string\_split(@InvoiceUIDList, ','));

DROP TABLE IF #InvoiceExpenseSku가 존재하면 삭제합니다;
CREATE TABLE #InvoiceExpenseSku(
RowNo INT
, InvoiceExpenseID INT
, SkuID2 INT
, MetricID INT
, [Date] DATE
, Value DECIMAL(18,5)
);

INSERT #InvoiceExpenseSku
SELECT
e.RowNo
, e.InvoiceExpenseID
, et.P1SkuID2
, e.MetricID
, e.Date
, et.P1Value
FROM
#InvoiceExpense e
JOIN @ExpenseMetricSkuValueTable et ON
e.InvoiceExpenseID = et.InvoiceExpenseID
AND e.MetricID = et.MetricID
AND e.Date = et.Date
AND e.AllocationMethod = et.AllocationMethod
JOIN LP\_Sku px ON
px.MemberID = et.SkuMemberID
AND px.SkuID2 = e.SkuID2;

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
물리적 테이블에 병합
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/
DROP TABLE IF EXISTS #ChangeLog;
CREATE TABLE #ChangeLog (
ChangeType VARCHAR(10)
,