# `Fun_get_sProductId` (function)

> 根据工单材料表Id,查询对应产品名称


- **Type:** FUNCTION
- **Returns:** `longtext`
- **Deterministic:** NO
- **SQL data access:** CONTAINS SQL

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sWorkOrderMaterialsId` | `varchar(200)` |

## Body

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

## Narrative

**Business context:** 工单 (work-order) — given a `mftworkordermaterials.sId`, resolves the `sProductId` (customer product) that owns this material line. Handles the "merged-job" (合版/拼版) case where one work-order combines multiple slave products, so the material may need to be attributed to the right slave's product.

**What it does:** reads `sParentId` (work-order id) and `sType` from `mftworkordermaterials`. If `sType=2`, joins via `M.sCombinePartsName = S.sId` to `mftworkorderslave`. Otherwise chains `mftworkordermaterials → mftworkordercontrol → mftworkordercontrolcombine → mftworkorderslave` on `sControlId`/`sSlaveId`. Falls back to "first slave under the same work-order" if neither produces a hit. Returns `sProductId`.

**Invocation:** Status: appears orphaned. No caller found in any channel (form-master, gdsmodule hooks, other routines, exhaustive xly-src grep) — candidate for maintainer audit. Sibling functions `Fun_get_sProductId_WM` and `Fun_get_sProductId_WP` (in `script/标版/upgrade/合版信息取客户产品/`) cover the same query for material/process tables under the `_WM`/`_WP` naming; this earlier-named variant looks superseded.
