# `Sp_SplicingTableSql` (procedure) - **Type:** PROCEDURE - **Deterministic:** NO - **SQL data access:** CONTAINS SQL ## Parameters | # | Mode | Name | Type | |---|---|---|---| | 1 | IN | `sFormGuid` | `varchar(50)` | | 2 | IN | `sTemplateGuid` | `varchar(50)` | | 3 | IN | `p_sWhere` | `longtext` | | 4 | IN | `sLoginId` | `varchar(255)` | | 5 | IN | `sBrId` | `varchar(50)` | | 6 | IN | `sSuId` | `varchar(50)` | | 7 | OUT | `sReturn` | `text` | | 8 | OUT | `sCode` | `int` | ## Body _Body is not pre-cached. To inspect: `mysql --defaults-file=~/.my.cnf -e 'SHOW CREATE PROCEDURE `Sp_SplicingTableSql`'`._ ## Narrative **Business context:** 财务管理 → 凭证管理 — generic source-table → 凭证模板 (UdfVoucherTemplate) column-mapping SQL builder. Used by the universal voucher-generation flow to splice a per-form `SELECT ... INSERT INTO udfvoucherslave` based on which optional columns the source `gdsconfigformmaster` table actually has (sSlaveId, sWareHouseId, sMaterialsId, sCustomerId, sSupplyId, sBankId, sProductId, sInvoiceNo, sMemo, dCostMoney/dProfitLossMoney/dMaterialsMoney, dSlaveTotalMoney/dTotalMoney, …). **What it does:** Resolves `p_sSrcTableName` from `gdsconfigformmaster.sTbName WHERE sParentId=sFormGuid`; reads `p_sSumType` from `udfvouchertemplatemaster`; then conditionally appends to `p_sInsertSql` and `p_sSelectSql` via `EXISTS(... information_schema.COLUMNS WHERE COLUMN_NAME=...)` checks — every optional column on the source table becomes a paired insert+select term. Money columns fall through `dCostMoney → dProfitLossMoney → dMaterialsMoney` and `dSlaveTotalMoney → dTotalMoney → dProductMoney` cascades. Returns the assembled column-mapping SQL fragment via `sReturn` for the caller to assemble the final voucher-insert statement. **Invocation:** Called by `Sp_InsertVoucher_Universals_All` and `Sp_InsertVoucher_Universals_Pro` — the two universal voucher-generation procs that consume any audited business bill and emit 财务凭证. Install script: `script/标版/30100101/Sp_SplicingTableSql.sql`. No direct xly-src or `gdsmodule` binding — strictly an internal helper.