公司需要,需要同步库存数据,这就需要用SQL语句来写即时库存查询,用了Microsoft SQL Server Management Studio 来抓语句,抓了很久抓到如下语句:
SELECT
*
FROM
(
SELECT
t0.FMATERIALID fmaterialid_id,
t0.FSTOCKID fstockid_id,
t0.FSTOCKLOCID fstocklocid,
t0.FLOT flot_id,
t0.FSTOCKUNITID fstockunitid_id,
t0.FQTY fqty,
t0.FBASEUNITID fbaseunitid_id,
t0.FBASEQTY fbaseqty,
t0.FSTOCKORGID fstockorgid_id,
t0.FOWNERID fownerid_id,
t0.FSTOCKORGID fstockorgid,
t0.FSUMLEVEL fsumlevel,
st019.FOPCODE fstocklocid_1,
t0.FID fid,
ROW_NUMBER () OVER (ORDER BY t0.FID ASC) fidentityid
FROM
T_STK_INVSUMQUERY t0
LEFT OUTER JOIN T_BAS_FLEXVALUESDETAIL st019 ON t0.FSTOCKLOCID = st019.FID
WHERE
(
FTRANSID = 'e0b7a4a6d3a5b64111e94ed399db50db'
AND t0.FSTOCKORGID IN (
1,
100008,
100009,
100010,
101008,
101010,
134011,
134012,
134013,
134014,
134047,
310300,
329929,
329930,
329931,
329932,
329934,
329935,
329936,
329937,
329938,
329939,
329940,
329941,
329942,
0
)
)
) tlist
WHERE ((fidentityid >= 1) AND (fidentityid <= 10000))
红色部分为分页所取条数(1-10000),但是结果为:
虽然条数对的上 (跟金蝶云星空的客户端查询出来的比较) 不过却出不来其他关联的数据,后来又各种百度,有关金蝶云即时库存SQL语句的真是少之又少,调试很久又有如下语句:
SELECT
TI.FSTOCKORGID,
OL.FNAME fstockorgname,
M.FNUMBER '物料编码', --物料编码
ML.FNAME '物料名称',--物料名称
TSL.FNAME '仓库',--仓库
TI.FSTOCKLOCID '仓位ID',--仓位ID
TUL0.FNAME '库存主单位',--库存主单位
TI.FQTY '主单位库存量',
TUL1.FNAME '基本单位', --基本单位
TI.FBASEQTY '基本单位库存量',
TUL2.FNAME '库存辅单位',--库存辅单位
TI.FSECQTY '库存辅单位库存量',
TL.FNUMBER flotnumber,
TI.FAUXPROPID,
CASE
WHEN TMS.FISEXPPARTOFLOT = '1' THEN
CONVERT (
CHAR (10),
TL.FPRODUCEDATE,
20
)
ELSE
CONVERT (
CHAR (10),
TI.FPRODUCEDATE,
20
)
END fproducedate,
CASE
WHEN TMS.FISEXPPARTOFLOT = '1' THEN
CONVERT (CHAR(10), TL.FEXPIRYDATE, 20)
ELSE
CONVERT (CHAR(10), TI.FEXPIRYDATE, 20)
END fexpirydate,
TB.FNUMBER fbomnumber,--BOM编号
TSSL.FNAME fstockstatus,
TI.FOWNERTYPEID,
VO_L.FNAME fownername,
TI.FKEEPERTYPEID,--保管者类型
VK_L.FNAME fkeepername,
TMS.FSTOREURNUM,
TMS.FSTOREURNOM,
TMS.FISSNMANAGE,
TSK.FALLOWMINUSQTY,
TUS.FPRECISION fstkprecision,
TUS.FROUNDTYPE froundtype,
TUE.FPRECISION fsecprecision,
TI.FMTONO,
TI.FPROJECTNO,
TSUB.FBASELOCKQTY fbaselockqty,
TSUB.FSECLOCKQTY fseclockqty,
'' fstocklocname
FROM
AIS20181210113048.dbo.T_STK_INVENTORY TI
LEFT OUTER JOIN T_ORG_ORGANIZATIONS_L OL ON (
TI.FSTOCKORGID = OL.FORGID
AND OL.FLOCALEID = 2052
) --机构名称
INNER JOIN T_BD_MATERIAL M ON (
M.FMASTERID = TI.FMATERIALID
AND (
M.FUSEORGID = TI.FSTOCKORGID
OR EXISTS (
SELECT
1
FROM
T_META_BASEDATATYPE BT
WHERE
(
BT.FBASEDATATYPEID = 'BD_MATERIAL'
AND BT.FSTRATEGYTYPE = 1
)
)
)
)--物料
LEFT OUTER JOIN T_BD_MATERIAL_L ML ON (
M.FMATERIALID = ML.FMATERIALID
AND ML.FLOCALEID = 2052
)--物料名称、规格型号
INNER JOIN T_BD_MATERIALSTOCK TMS ON M.FMATERIALID = TMS.FMATERIALID
LEFT OUTER JOIN T_ENG_BOM TB ON (
TB.FMASTERID = TI.FBOMID
AND (
TB.FUSEORGID = TI.FSTOCKORGID
OR EXISTS (
SELECT
1
FROM
T_META_BASEDATATYPE BT
WHERE
(
BT.FBASEDATATYPEID = 'ENG_BOM'
AND BT.FSTRATEGYTYPE = 1
)
)
)
)
LEFT OUTER JOIN T_BD_STOCKSTATUS_L TSSL ON (
TI.FSTOCKSTATUSID = TSSL.FSTOCKSTATUSID
AND TSSL.FLOCALEID = 2052
)
LEFT OUTER JOIN T_BD_LOTMASTER TL ON (
(
TI.FLOT = TL.FMASTERID
AND TI.FSTOCKORGID = TL.FUSEORGID
)
AND TL.FBIZTYPE = '1'
)
LEFT OUTER JOIN T_BD_UNIT TUS ON TMS.FSTOREUNITID = TUS.FUNITID
LEFT OUTER JOIN T_BD_UNIT_L TUL0 ON (
TMS.FSTOREUNITID = TUL0.FUNITID
AND TUL0.FLOCALEID = 2052
)
INNER JOIN T_BD_STOCK TSK ON (
TSK.FMASTERID = TI.FSTOCKID
AND (
TSK.FUSEORGID = TI.FSTOCKORGID
OR EXISTS (
SELECT
1
FROM
T_META_BASEDATATYPE BT
WHERE
(
BT.FBASEDATATYPEID = 'BD_STOCK'
AND BT.FSTRATEGYTYPE = 1
)
)
)
)
LEFT OUTER JOIN T_BD_STOCK_L TSL ON (
TSL.FSTOCKID = TI.FSTOCKID
AND TSL.FLOCALEID = 2052
)
LEFT OUTER JOIN T_BD_UNIT_L TUL1 ON (
TI.FBASEUNITID = TUL1.FUNITID
AND TUL1.FLOCALEID = 2052
)
LEFT OUTER JOIN T_BD_UNIT TUE ON TMS.FAUXUNITID = TUE.FUNITID
LEFT OUTER JOIN T_BD_UNIT_L TUL2 ON (
TI.FSECUNITID = TUL2.FUNITID
AND TUL2.FLOCALEID = 2052
)
LEFT OUTER JOIN V_ITEMCLASS_OWNER VO ON (
(
VO.FMASTERID = TI.FOWNERID
AND VO.FFORMID = TI.FOWNERTYPEID
)
AND (
VO.FUSEORGID = TI.FSTOCKORGID
OR VO.FUSEORGID = 0
OR EXISTS (
SELECT
1
FROM
T_META_BASEDATATYPE BT
WHERE
(
BT.FBASEDATATYPEID = VO.FFORMID
AND BT.FSTRATEGYTYPE = 1
)
)
)
)
LEFT OUTER JOIN V_ITEMCLASS_OWNER_L VO_L ON (
VO.FITEMID = VO_L.FITEMID
AND VO_L.FLOCALEID = 2052
)
LEFT OUTER JOIN V_ITEMCLASS_KEEPER VK ON (
(
VK.FMASTERID = TI.FKEEPERID
AND VK.FFORMID = TI.FKEEPERTYPEID
)
AND (
VK.FUSEORGID = TI.FSTOCKORGID
OR VK.FUSEORGID = 0
OR EXISTS (
SELECT
1
FROM
T_META_BASEDATATYPE BT
WHERE
(
BT.FBASEDATATYPEID = VK.FFORMID
AND BT.FSTRATEGYTYPE = 1
)
)
)
)
LEFT OUTER JOIN V_ITEMCLASS_KEEPER_L VK_L ON (
VK.FITEMID = VK_L.FITEMID
AND VK_L.FLOCALEID = 2052
)
--以下仓位
LEFT OUTER JOIN T_BAS_FLEXVALUESDETAIL FVD ON TI.FSTOCKLOCID = FVD.FID
LEFT OUTER JOIN T_BAS_FLEXVALUESENTRY_L VFF100001 ON (
FVD.FOPCODE = VFF100001.FENTRYID
AND VFF100001.FLOCALEID = 2052
)
LEFT OUTER JOIN T_BAS_FLEXVALUESENTRY_L VFF100002 ON (
FVD.FOPCODE = VFF100002.FENTRYID
AND VFF100002.FLOCALEID = 2052
)
LEFT OUTER JOIN T_BAS_FLEXVALUESENTRY_L VFF100003 ON (
FVD.FOPCODE = VFF100003.FENTRYID
AND VFF100003.FLOCALEID = 2052
)
--以下锁库和预留
LEFT OUTER JOIN (
SELECT
TLKE.FSUPPLYINTERID finventryid,
SUM (TLKE.FBASEQTY) fbaselockqty,
SUM (TLKE.FSECQTY) fseclockqty
FROM
T_PLN_RESERVELINKENTRY TLKE
INNER JOIN T_PLN_RESERVELINK TLKH ON TLKE.FID = TLKH.FID
WHERE
(
TLKE.FSUPPLYFORMID = 'STK_Inventory'
AND TLKE.FLINKTYPE = '4'
)
GROUP BY
TLKE.FSUPPLYINTERID
) tsub ON TI.FID = TSUB.FINVENTRYID
WHERE TI.FBASEQTY > 0
以上这条语句是自己调试出来的,不过条数比第一个多了40几条(共3w多条),但是该有的都有,所以这个暂时就采用了,之后调试或者测试的时候估计还会继续修改,暂时到这里