两条SQL语句都可以查询
SELECT [单据类型] ,[单据号],
(CASE WHEN [仓库]=‘10’ then ‘原料仓’
when [仓库]=‘20’ then ‘半成品仓’
when [仓库]=‘30’ then ‘成品仓’
when [仓库]=‘40’ then ‘产线不良仓’
when [仓库]=‘50’ then ‘研发仓’
when [仓库]=‘60’ then ‘车间仓’
when [仓库]=‘70’ then ‘来料不良’
when [仓库]=‘80’ then ‘返修良品’
when [仓库]=‘81’ then ‘返修不良’
when [仓库]=‘90’ then ‘售后仓’
when [仓库]=‘91’ then ‘销售服务仓’ END) as [仓库] ,
(CASE WHEN [收发类别]=‘202’ THEN ‘普通销售出库’
WHEN [收发类别]=‘203’ THEN ‘委外发料’
WHEN [收发类别]=‘204’ THEN ‘调拨出库’
WHEN [收发类别]=‘205’ THEN ‘委外发料’
WHEN [收发类别]=‘206’ THEN ‘生产补料’
WHEN [收发类别]=‘207’ THEN ‘辅料领用’
WHEN [收发类别]=‘208’ THEN ‘研发领料’
WHEN [收发类别]=‘209’ THEN ‘委外补料’
WHEN [收发类别]=‘210’ THEN ‘部门领料’
WHEN [收发类别]=‘211’ THEN ‘借出领料’
WHEN [收发类别]=‘212’ THEN ‘客供料出库’
WHEN [收发类别]=‘213’ THEN ‘售后领料’
WHEN [收发类别]=‘298’ THEN ‘其他出库’
WHEN [收发类别]=‘299’ THEN ‘报废出库’
END) as [收发类别] ,
[存货编码] ,[数量], [累计出库辅计量数量],[实际数量], [代管结算数量], [应收应发数量], [日期], [部门], [制单人] ,[制单日期] FROM
(SELECT cBusType as [单据类型] ,cCode as [单据号], cWhCode AS [仓库],cRdCode AS [收发类别], cInvCode AS [存货编码] , iQuantity AS [数量],iSOutNum AS [累计出库辅计量数量],iFQuantity[实际数量], iVMISettleQuantity [代管结算数量],iNQuantity [应收应发数量], dDate AS [日期], cDepCode AS [部门],cMaker AS [制单人] ,dnmaketime AS [制单日期] FROM RdRecordS08 RS8 INNER JOIN rdrecord08 R8 ON RS8.ID=R8.ID
UNION
SELECT cBusType as [单据类型] ,cCode as [单据号], cWhCode AS [仓库],cRdCode AS [收发类别], cInvCode AS [存货编码] , iQuantity AS [数量],iSOutNum AS [累计出库辅计量数量],iFQuantity[实际数量], iVMISettleQuantity [代管结算数量],iNQuantity [应收应发数量], dDate AS [日期], cDepCode AS [部门],cMaker AS [制单人] ,dnmaketime AS [制单日期] FROM rdrecords09 RS9 INNER JOIN RdRecord09 R9 ON RS9.ID=R9.ID
UNION
2、出入库明细
SELECT cBusType as [单据类型] ,cCode as [单据号], cWhCode AS [仓库],cRdCode AS [收发类别], cInvCode AS [存货编码] , iQuantity AS [数量],iSOutNum AS [累计出库辅计量数量],iFQuantity[实际数量], iVMISettleQuantity [代管结算数量],iNQuantity [应收应发数量], dDate AS [日期], cDepCode AS [部门],cMaker AS [制单人] ,dnmaketime AS [制单日期] FROM rdrecords10 RS10 INNER JOIN rdrecord10 R10 ON RS10.ID=R10.ID
UNION
SELECT cBusType as [单据类型] ,cCode as [单据号], cWhCode AS [仓库],cRdCode AS [收发类别], cInvCode AS [存货编码] , iQuantity AS [数量],iSOutNum AS [累计出库辅计量数量],iFQuantity[实际数量], iVMISettleQuantity [代管结算数量],iNQuantity [应收应发数量], dDate AS [日期], cDepCode AS [部门],cMaker AS [制单人] ,dnmaketime AS [制单日期] FROM RdRecordS11 RS11 INNER JOIN rdrecord11 R11 ON RS11.ID=R11.ID
UNION
SELECT cBusType as [单据类型] ,cCode as [单据号], cWhCode AS [仓库],cRdCode AS [收发类别], cInvCode AS [存货编码] , iQuantity AS [数量],iSOutNum AS [累计出库辅计量数量],iFQuantity[实际数量], iVMISettleQuantity [代管结算数量],iNQuantity [应收应发数量], dDate AS [日期], cDepCode AS [部门],cMaker AS [制单人] ,dnmaketime AS [制单日期] FROM rdrecords01 RS01 INNER JOIN rdrecord01 R01 ON RS01.ID=R01.ID )
AS T
WHERE 存货编码 =‘3008040100’