2013-09-23 45 views
1
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#代碼中看起來像這樣。存儲過程使用IF語句,然後創建虛擬表拿起數據

SFC_spViewPO_Select(1,parameter1,parameter2,parameter3 .. etc ..)然後另一個用於 SFC_spViewPO_Select(2,parameter1,parameter2,parameter3 .. etc ..)..第一個在參數所述存儲過程應該指示我在SQL Server存儲過程中設置的IF語句,然後跟蹤我在if語句中創建的虛擬表的參數條件是否可能我一直試圖弄清楚這個東西是如何工作的,但是:(幫助!

回答

1

您需要將if語句之外的語句(在IF之前)或在之後的IF語句中移動聲明語句聲明。

相關問題