|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册账号
×
/*在常规情况下,现存量不能按照部门查询,如想对多个仓库同时查询有点麻烦,这条SQL可以解决*/
SELECT dbo.Warehouse.cWhCode AS 仓库编码,dbo.Warehouse.cWhName AS 仓库名称, dbo.Warehouse.cDepCode AS 部门编码,Dep.cDepName AS 部门名称,
dbo.CurrentStock.cInvCode AS 存货编码,
dbo.Inventory.cInvAddCode AS 存货代码,dbo.InventoryClass.cinvcname AS 存货分类,dbo.Inventory.cInvStd AS 规格型号,
dbo.Inventory.cInvName AS 存货名称,Unit.cComUnitName AS 计量单位,
dbo.Inventory.cInvDefine6 AS 自定义项6,dbo.Inventory.iInvSPrice AS 参考成本,
SUM(ISNULL(dbo.CurrentStock.iQuantity, 0)) AS 现存量,
dbo.Inventory.iInvSPrice*SUM(ISNULL(dbo.CurrentStock.iQuantity, 0)) AS 成本价值
FROM dbo.CurrentStock
INNER JOIN dbo.Inventory ON dbo.CurrentStock.cInvCode = dbo.Inventory.cInvCode
INNER JOIN dbo.Warehouse ON dbo.Warehouse.cWhCode = dbo.CurrentStock.cWhCode
INNER JOIN dbo.ComputationUnit Unit ON dbo.Inventory.cComUnitCode = Unit.cComunitCode
INNER JOIN InventoryClass ON left(Inventory.cInvCCode,6) = InventoryClass.cInvCCode
INNER JOIN dbo.Department Dep ON dbo.Warehouse.cDepCode = Dep.cDepCode
GROUP BY dbo.Warehouse.cWhCode,dbo.Warehouse.cWhName, dbo.Warehouse.cDepCode, Dep.cDepName,
dbo.CurrentStock.cInvCode,
dbo.Inventory.cInvAddCode,dbo.InventoryClass.cinvcname,
dbo.Inventory.cInvName,Unit.cComUnitName,
dbo.Inventory.cInvDefine6,dbo.Inventory.iInvSPrice,
dbo.Inventory.cInvStd,dbo.CurrentStock.cBatch, dbo.CurrentStock.cFree1
having SUM(ISNULL(dbo.CurrentStock.iQuantity, 0)) >0
/*
|
|