如何从存储过程中删除参数

时间:2018-02-03 12:21:47

标签: sql stored-procedures parameters firebird

我正在使用具有存储过程的firebird数据库2.5。当我运行它时,它会询问我三个参数(FITEMNO,FDATE from和TDATE)。给出参数后,它显示相关的数据/网格。我想从存储过程中删除这些参数,以便我可以看到所有数据。这是程序

    declare variable FID Integer;
     declare variable ExistITem Integer;
     declare variable FSIID Integer;
begin
ITEMNO=FITEMNO;
  for select D.ARInvoiceID, D.Seq,
    D.ITEMRESERVED1, D.ITEMRESERVED2, D.ITEMRESERVED3, D.ITEMRESERVED4, D.ITEMRESERVED5,
    D.ITEMRESERVED6, D.ITEMRESERVED7, D.ITEMRESERVED8, D.ITEMRESERVED9, D.ITEMRESERVED10, D.WAREHOUSEID,
    D.QUANTITY, D.DEPTID, D.PROJECTID, D.BRUTOUNITPRICE, D.ITEMUNIT, D.TAXCODES, D.ITEMDISCPC, D.QTYCONTROL, D.ITEMOVDESC,
    D.DOID, D.DOSEQ, D.SOID, D.SOSEQ
    from ARINVDET D inner join ARINV M on M.ARINVOICEID=D.ARINVOICEID
    where D.ITEMNO=:ITEMNO and M.DeliveryOrder=0 and InvoiceDate between :FDate and :TDate --and GroupSeq+0 is null
      into :FID, :SEQ, :ITEMRESERVED1, :ITEMRESERVED2, :ITEMRESERVED3, :ITEMRESERVED4, :ITEMRESERVED5,
    :ITEMRESERVED6, :ITEMRESERVED7, :ITEMRESERVED8, :ITEMRESERVED9, :ITEMRESERVED10, :WAREHOUSEID,
    :INVQTY, :DEPTID, :PROJECTID, :UNITPRICE, :ITEMUNIT, :TAXCODES, :ITEMDISCPC, :QTYCONTROL, :ITEMOVDESC,
    :DOID, :DOSEQ, :SOID, :SOSEQ do begin
    select Result,DiscLvl1,DiscLvl2,DiscLvl3,DiscLvl4,DiscLvl5
      from CalcPercent(:ITEMDISCPC, :UNITPRICE) into :ITEMDISC,:DiscLvl1,:DiscLvl2,:DiscLvl3,:DiscLvl4,:DiscLvl5;
    ITEMDISC  = cast(INVQTY as double precision) * cast(ITEMDISC as double precision);
    DiscLvl1  = cast(INVQTY as double precision) * cast(DiscLvl1 as double precision);
    DiscLvl2  = cast(INVQTY as double precision) * cast(DiscLvl2 as double precision);
    DiscLvl3  = cast(INVQTY as double precision) * cast(DiscLvl3 as double precision);
    DiscLvl4  = cast(INVQTY as double precision) * cast(DiscLvl4 as double precision);
    DiscLvl5  = cast(INVQTY as double precision) * cast(DiscLvl5 as double precision);
    EXTAMOUNT = (cast(INVQTY as double precision) * cast(UNITPRICE as double precision)) - ITEMDISC;
    select INVOICENO, INVOICEDATE, DESCRIPTION, CUSTOMERID, SALESMANID from ARINV where ARINVOICEID=:FID
      into :INVOICENO, :INVOICEDATE, :INVOICEDESCRIPTION, :PERSONID, :SALESMANID;
    INVOICETYPE = 0;
    INVOICEID = FID;
    SALESINVOICEID = FID;
    select max(d.PAYMENTID) from arinvpmt d inner join ARPMT m on m.PaymentID=d.PaymentID
      where m.FiscalPmt=0 and d.ARINVOICEID=:FID into :LASTPAYMENTID;
    if (LASTPAYMENTID is null) then
      LASTPAYMENTID = -1;
    select SalesQty, SalesAmount, COGSAmount from Get_SalesItemARINV(:ITEMNO,:FID, :SEQ)
           into :SALESQTY, :SALESAMOUNT, :COGSAMOUNT;
    GROSSPROFIT = SALESAMOUNT - COGSAMOUNT;
    GROSSPROFITPERCENT = 0;
    if (SALESAMOUNT <> 0) then
      GROSSPROFITPERCENT = (cast(GROSSPROFIT as double Precision)/cast(SALESAMOUNT as double precision)) * 100;
    suspend;
  end
  for select D.ARRefundID, D.Seq, S.ARINVOICEID,
    D.ITEMRESERVED1, D.ITEMRESERVED2, D.ITEMRESERVED3, D.ITEMRESERVED4, D.ITEMRESERVED5,
    D.ITEMRESERVED6, D.ITEMRESERVED7, D.ITEMRESERVED8, D.ITEMRESERVED9, D.ITEMRESERVED10, D.WAREHOUSEID,
    D.Quantity, D.DEPTID, D.PROJECTID, D.BRUTTOUNITPRICE, D.ITEMUNIT, D.TAXCODES, D.ITEMDISCPC, D.QTYCONTROL, D.ITEMOVDESC
    from ARREFDET D inner join ARREFUND M on M.ARRefundID=D.ARRefundID
    inner join ARINV S on S.ARINVOICEID=M.ARINVOICEID and S.DeliveryOrder=0
    where D.ITEMNO=:ITEMNO and M.InvoiceDate between :FDate and :TDate --and GroupSeq+0 is null
      into :FID, :SEQ, :FSIID, :ITEMRESERVED1, :ITEMRESERVED2, :ITEMRESERVED3, :ITEMRESERVED4, :ITEMRESERVED5,
    :ITEMRESERVED6, :ITEMRESERVED7, :ITEMRESERVED8, :ITEMRESERVED9, :ITEMRESERVED10, :WAREHOUSEID,
    :INVQTY, :DEPTID, :PROJECTID, :UNITPRICE, :ITEMUNIT, :TAXCODES, :ITEMDISCPC, :QTYCONTROL, :ITEMOVDESC do begin
    select Result,DiscLvl1,DiscLvl2,DiscLvl3,DiscLvl4,DiscLvl5
      from CalcPercent(:ITEMDISCPC, :UNITPRICE) into :ITEMDISC,:DiscLvl1,:DiscLvl2,:DiscLvl3,:DiscLvl4,:DiscLvl5;
    ITEMDISC  = - cast(INVQTY as double precision) * cast(ITEMDISC as double precision);
    DiscLvl1  = - cast(INVQTY as double precision) * cast(DiscLvl1 as double precision);
    DiscLvl2  = - cast(INVQTY as double precision) * cast(DiscLvl2 as double precision);
    DiscLvl3  = - cast(INVQTY as double precision) * cast(DiscLvl3 as double precision);
    DiscLvl4  = - cast(INVQTY as double precision) * cast(DiscLvl4 as double precision);
    DiscLvl5  = - cast(INVQTY as double precision) * cast(DiscLvl5 as double precision);
    EXTAMOUNT = (cast(INVQTY as double precision) * cast(UNITPRICE as double precision)) + ITEMDISC;
    select INVOICENO, INVOICEDATE, DESCRIPTION, CUSTOMERID, SALESMANID from ARREFUND R where ARREFUNDID=:FID
      into :INVOICENO, :INVOICEDATE, :INVOICEDESCRIPTION, :PERSONID, :SALESMANID;
    INVOICETYPE = 1;
    INVOICEID = FID;
    SALESINVOICEID = FSIID;
    LASTPAYMENTID = -1;
    select SalesQty, SalesAmount, COGSAmount from Get_SalesItemARRefund(:ITEMNO,:FID, :SEQ)
           into :SALESQTY, :SALESAMOUNT, :COGSAMOUNT;
    GROSSPROFIT = SALESAMOUNT - COGSAMOUNT;
    GROSSPROFITPERCENT = 0;
    if (SALESAMOUNT <> 0) then
      GROSSPROFITPERCENT = (cast(GROSSPROFIT as double Precision)/cast(SALESAMOUNT as double precision)) * 100;
    suspend;
  end
end

如何删除参数以查看适用于View的所有数据? (我使用Upscene Database Workbench 5进行数据库管理)

1 个答案:

答案 0 :(得分:0)

我理解你的问题的一种方法是你希望程序不考虑你的参数。

您可以发送NULL参数并在其中执行类似的操作: where(FIELD =:PARAM)或(:PARAM IS NULL)

/*From the first SELECT statement in your example */
select d.arinvoiceid, d.seq, d.itemreserved1, d.itemreserved2, ...
from arinvdet d
inner join arinv m on m.arinvoiceid = d.arinvoiceid
where
((d.itemno = :itemno) or (:itemno is null)) and
m.deliveryorder = 0 and
((invoicedate between :fdate and :tdate) or (:fdate is null) or (:tdate is null))
into ...