【发布时间】:2014-04-07 01:25:24
【问题描述】:
declare @ProductDetails as table(ProductName nvarchar(200),ProductDescription nvarchar(200),
Brand nvarchar(200),
Categry nvarchar(200),
Grop nvarchar(200),
MRP decimal,SalesRate decimal,CurrentQuantity decimal,AvailableQty decimal)
declare @AvailableQty table(prcode nvarchar(100),Aqty decimal)
declare @CloseStock table(pcode nvarchar(100),
Cqty decimal)
insert into @CloseStock
select PCODE ,
0.0
from producttable
insert into @AvailableQty
select PCODE ,
0.0
from producttable
--Current Qty
--OpenQty
update @CloseStock set Cqty=((OOQTY+QTY+SRRQTY+PYQTY)-(STQTY+PRRQTY))
from
(
select PC.PCODE as PRODUCTCODE,
--Opening
(select case when SUM(PU.Quantity)is null then 0 else SUM(PU.Quantity) end as Q from ProductOpeningYearEnd PU
where PC.PCODE=PU.ProductName) as OOQTY,
--Purchase
(select case when SUM(PU.quantity)is null then 0 else SUM(PU.quantity) end as Q from purchase PU
where PC.PCODE=PU.prdcode ) as QTY,
--Sales
(select case when SUM(ST.QUANTITY)is null then 0 else SUM(ST.QUANTITY)end as Q2 from salestable ST
where PC.PCODE=ST.PRODUCTCODE and ST.status!='cancel' )as STQTY,
--Physical Stock
(select case when SUM(PS.Adjustment)is null then 0 else SUM(PS.Adjustment)end as Q3 from physicalstock PS
where PC.PCODE=PS.PCODE )as PYQTY,
--Sales Return
(select case when SUM(SR.quantity)is null then 0 else SUM(SR.quantity)end as Q3 from salesreturn SR
where PC.PCODE=SR.prdcode )as SRRQTY,
--Purchase Return
(select case when SUM(PR.quantity)is null then 0 else SUM(PR.quantity)end as Q3 from purchasereturn PR
where PC.PCODE=PR.prdcode )as PRRQTY
from producttable PC
group by PC.PCODE
)t
where PCODE=t.PRODUCTCODE
--Available
update @AvailableQty set Aqty=((CCqty-GIQty)+(GOQty))
--((OOQTY+QTY+SRRQTY+PYQTY)-(STQTY+PRRQTY))
from
(
select PC.PCODE as PRODUCTCODE,
--GoodsIn
(select case when SUM(GI.quantity)is null then 0 else SUM(GI.quantity) end as Q from goodsin GI
where PC.PCODE=GI.productcode) as GIQty,
--GoodsOut
(select case when SUM(GUT.quantity)is null then 0 else SUM(GUT.quantity) end as Q from goodsout GUT
where PC.PCODE=GUT.productcode ) as GOQty,
--Current Stock
(select CS.Cqty as Q from @CloseStock CS
where PC.PCODE=CS.pcode ) as CCqty
from producttable PC
group by PC.PCODE
)t
where prcode=t.PRODUCTCODE
insert into @ProductDetails
select PCODE,[DESCRIPTION],BRAND,CATEGORY,DEPARTMENT,MRP,SALERATE,0,0
from producttable
update @ProductDetails set CurrentQuantity=pcqty,AvailableQty=acqty
from
(
select pt.ProductName as pn,cs.Cqty as pcqty,ac.Aqty as acqty from @ProductDetails pt
inner join @CloseStock cs on pt.ProductName=cs.pcode
inner join @AvailableQty ac on pt.ProductName=ac.prcode
)t
where ProductName=t.pn
select * from @ProductDetails
end
这在 pcode 字段中添加 ant (-.&) 时不起作用,我什至想在 pcode 字段中允许这种符号, 请帮助我如何在查询中允许任何符号
(此代码有问题) 更新@AvailableQty 设置Aqty=((CCqty-GIQty)+(GOQty)) 从 ( 选择 PC.PCODE 作为 PRODUCTCODE, --GoodsIn (选择 SUM(GI.quantity) 为 null 然后为 0 的情况,否则 SUM(GI.quantity) 以 G 中的货物 Q 结尾 其中 PC.PCODE=GI.productcode) 作为 GIQty, --GoodsOut (选择 SUM(GUT.quantity) 为 null 然后为 0 的情况,否则 SUM(GUT.quantity) 以来自货物 GUT 的 Q 结尾 其中 PC.PCODE=GUT.productcode ) 为 GOQty, --当前库存 (从@CloseStock CS 中选择 CS.Cqty 作为 Q 其中 PC.PCODE=CS.pcode ) 为 CCqty 从产品table PC 按 PC.PCODE 分组 )t 其中 prcode=t.PRODUCTCODE
【问题讨论】:
-
我不知道您为什么会收到该消息,但此
Cqty=((OOQTY+QTY+SRRQTY+PYQTY)-(STQTY+PRRQTY))不起作用。您正在引用 INLINE VIEW 别名,就好像它们是字段一样。这些字段在任何情况下都无法寻址,因为您没有在内联视图t中选择它们。