# `fun_getaccordercostanalysiscost_diff` (function)

> 获取成本误差


- **Type:** FUNCTION
- **Returns:** `decimal(18,6)`
- **Deterministic:** NO
- **SQL data access:** CONTAINS SQL

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `p_dExpenseMoney` | `decimal(18,6)` |
| 2 | IN | `p_sWorkCenterId` | `varchar(50)` |
| 3 | IN | `p_sColumnName` | `varchar(50)` |

## Body

_Body is not pre-cached. To inspect: `mysql --defaults-file=~/.my.cnf -e 'SHOW CREATE FUNCTION `fun_getaccordercostanalysiscost_diff`'`._

## Narrative

**Business context:** Cost-accounting variance helper — `获取成本误差`. Compares one expense column on `accexpenseentrydepartmentmaster_dif` (the per-workcenter cost-difference ledger) against the booked expense amount and returns the residual.

**What it does:** reads `dTotalMoney` from `accexpenseentrydepartmentmaster_dif` keyed by `sColumnName` + `sWorkCenterId`. If non-zero, returns `dTotalMoney - p_dExpenseMoney`; otherwise returns 0.

**Invocation:** called from `Sp_CostAccount_WorkCenterToOperation_Event` (work-center → operation cost-allocation event) and `Sp_System_ProductionCost` (production-cost rollup) — both part of the cost-accounting subsystem (`Sp_System_ProductionCost` itself has `Sp_System_ProductionCostBak`, `_new`, `_24222`, `Test` siblings indicating active iteration).
