SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[SFC_spViewPO_Select]
(@trans int = NULL)
as
begin
IF @trans = 1
DECLARE @AutoRR TABLE
(
spPONumber nvarchar (30)
,spItemnmbr nvarchar (20)
,spItemDesc nvarchar (65)
,spUofM nvarchar (20)
,spLocncode nvarchar (20)
,spUnitCost float
,spPurchase float
,spReceive float
,spReceiveTmp float
,spOrd int
,spCancel float
,spVendID nvarchar (20)
)
BEGIN
INSERT INTO @AutoRR
(
spPONumber,
spItemnmbr,
spItemDesc,
spUofM,
spLocncode,
spUnitCost,
spPurchase,
spReceive,
spReceiveTmp,
spOrd,
spVendID
)
SELECT PONUMBER,
ITEMNMBR,
ITEMDESC,
UOFM,
LOCNCODE,
CASE WHEN Adjustedprice=0 then UNITCOST else AdjustedPrice end,
QTYORDER-QTYCANCE,
0,
0,
ord,
VendorID
FROM POP10110
WHERE (VENDORID ='KORGRO01 ') AND
EXISTS(Select * from pop10100 where (Ponumber = POP10110.PoNumber) AND
(POSTSTATUS=1) AND
(POSTATUS < 4) AND
(Revision_Number <> 1))
INSERT INTO @AutoRR
(
spPONumber,
spItemnmbr,
spItemDesc,
spUofM,
spLocncode,
spUnitCost,
spPurchase,
spReceive,
spReceiveTmp,
spOrd,
spVendID
)
SELECT POP10110.PONumber,
POP10110.ITEMNMBR,
POP10110.ITEMDESC,
POP10110.UOFM,
POP10110.LOCNCODE,
CASE WHEN POP10110.Adjustedprice=0 then POP10110.UNITCOST else POP10110.AdjustedPrice end,
0,
SUM(POP10500.QTYSHPPD),
0,
POP10110.Ord,
POP10110.VendorID
FROM POP10110 INNER JOIN
POP10500 ON POP10110.PONUMBER = POP10500.PONUMBER AND POP10110.ORD = POP10500.POLNENUM
WHERE (POP10110.VendorID='KORGRO01 ') AND
EXISTS(Select * from pop10100 where (Ponumber = POP10500.PoNumber) AND
(POSTSTATUS=1) AND
(POSTATUS < 4) AND
(Revision_Number <> 1))
GROUP BY POP10110.ITEMNMBR,
POP10110.ITEMDESC,
POP10110.UOFM,
POP10110.LOCNCODE,
POP10110.UNITCOST,
POP10110.PONumber,
POP10110.Ord,
POP10110.Adjustedprice,
POP10110.VendorID
INSERT INTO @AutoRR
(
spPONumber,
spItemnmbr,
spItemDesc,
spUofM,
spLocncode,
spUnitCost,
spPurchase,
spReceive,
spReceiveTmp,
spOrd,
spVendID
)
SELECT ponumber,
Itemnmbr,
ItemDesc,
UofM,
Locncode,
UnitCost,
0,
0,
Quantity,
ord,
VendorID
FROM POPTEMPRECV
WHERE VendorID='KORGRO01 '
SELECT spPONumber as ponumber,
spItemnmbr as itemnmbr,
spItemDesc as itemdesc,
spUofM as uofm,
spLocncode as locncode,
spUnitCost as UnitCost,
SUM(spPurchase) - (SUM(spReceive) + SUM(spReceiveTmp)) as Balance,
spORd as ORD,
SUM(spPurchase) AS TotalPO,
spVendID
FROM @AutoRR
WHERE spVendID = 'KORGRO01 '
GROUP BY spPONumber,
spItemnmbr,
spItemDesc,
spUofM,
spLocncode,
spUnitCost,
spOrd,
spVendID
HAVING SUM(spPurchase) - (SUM(spReceive) + SUM(spReceiveTmp)) > 0
END
ELSE IF @trans = 2
DECLARE @AutoRRII TABLE
(
spPONumber nvarchar (30)
,spItemnmbr nvarchar (20)
,spItemDesc nvarchar (65)
,spUofM nvarchar (20)
,spLocncode nvarchar (20)
,spUnitCost float
,spPurchase float
,spReceive float
,spReceiveTmp float
,spOrd int
,spCancel float
,spVendID nvarchar (20)
)
BEGIN
-- ANOTHER STORE PROCEDURE WITH DIFFERENT CREATED VIRTUAL TABLE...
END
END
尝试执行此方法,但在调用我的存储过程虚拟表上的参数后,它在 c# 上不起作用。我在想,在连接它们之后,我的 c# 代码可能看起来像这样。
SFC_spViewPO_Select(1, parameter1, parameter2, parameter3.. etc..) 然后另一个 SFC_spViewPO_Select(2, parameter1, parameter2, parameter3.. etc..).. 在所述存储过程的参数中找到的第一个数字应该指示我在 SQL Server 存储过程中设置的 IF 语句,然后跟踪我在 if 语句中创建的虚拟表的参数还好.. :( 帮助!