更改存储过程

时间:2009-11-12 20:39:32

标签: sql oracle stored-procedures

我有一个proc打印检查是否有新的支票要打印。如果没有什么可以发行新的支票,它就不会打印任何。现在我想修改这个过程,即使我没有任何新的支票要打印,它应该至少拿起一张支票进行打印。(即使它已经打印过)。你能告诉我怎么做吗?这是存储过程。

CREATE PROCEDURE [proc_1250_SELCashiersChecksForPrint] AS

SELECT t_DATA_CashiersChecksIssued.ControlNbr, 
    t_DATA_CashiersChecksIssued.Audit_DateAdded, 
    t_DATA_CashiersChecksIssued.BatchNbr, 
    t_DATA_CashiersChecksIssued.SerialNbr, 
    t_DATA_CashiersChecksIssued.CheckRTN, 
    t_DATA_CashiersChecksIssued.CheckAccountNbr, 
    t_DATA_CashiersChecksIssued.Amount, 
    t_DATA_CashiersChecksIssued.DateIssued, 
    t_DATA_CashiersChecksIssued.Payee, 
    t_DATA_CashiersChecksIssued.Address, 
    t_DATA_CashiersChecksIssued.City, 
    t_DATA_CashiersChecksIssued.State, 
    t_DATA_CashiersChecksIssued.Zip, 
    t_DATA_Reclamation.ClaimId, 
    t_DATA_Reclamation.NoticeDate, 
    t_DATA_Reclamation.FirstName, 
    t_DATA_Reclamation.MiddleName, 
    t_DATA_Reclamation.LastName, 
    t_DATA_Reclamation.ClaimTotal, 
    t_PCD_Claimant.Name AS Agency, 
    t_DATA_CashiersChecksIssued.IDENTITYCOL
FROM t_DATA_CashiersChecksIssued INNER JOIN
    t_DATA_Reclamation ON 
    t_DATA_CashiersChecksIssued.ControlNbr = t_DATA_Reclamation.ControlNbr
     INNER JOIN
    t_PCD_Claimant ON 
    t_DATA_Reclamation.ClaimantCode = t_PCD_Claimant.ClaimantCode
WHERE (t_DATA_CashiersChecksIssued.SerialNbr IS NULL) AND 
    (t_DATA_CashiersChecksIssued.DateIssued IS NULL)
ORDER BY t_DATA_CashiersChecksIssued.Audit_DateAdded ASC, 
         t_DATA_CashiersChecksIssued.ControlNbr ASC

如果您需要更多信息,请与我们联系。

3 个答案:

答案 0 :(得分:1)

SELECT TOP 1 t_DATA_CashiersChecksIssued.ControlNbr,               t_DATA_CashiersChecksIssued.Audit_DateAdded,               t_DATA_CashiersChecksIssued.BatchNbr,                   t_DATA_CashiersChecksIssued.SerialNbr,                   t_DATA_CashiersChecksIssued.CheckRTN,                   t_DATA_CashiersChecksIssued.CheckAccountNbr,                   t_DATA_CashiersChecksIssued.Amount,                   t_DATA_CashiersChecksIssued.DateIssued,                   t_DATA_CashiersChecksIssued.Payee,t_DATA_CashiersChecksIssued.Address,                   t_DATA_CashiersChecksIssued.City,t_DATA_CashiersChecksIssued.State,                   t_DATA_CashiersChecksIssued.Zip,t_DATA_Reclamation.ClaimId,                   t_DATA_Reclamation.NoticeDate,t_DATA_Reclamation.FirstName,                   t_DATA_Reclamation.MiddleName,t_DATA_Reclamation.LastName,                   t_DATA_Reclamation.ClaimTotal,t_PCD_Claimant.Name AS Agency,                   t_DATA_CashiersChecksIssued.IDENTITYCOL       FROM t_DATA_CashiersChecksIssued       INNER JOIN t_DATA_Reclamation ON t_DATA_CashiersChecksIssued.ControlNbr = t_DATA_Reclamation.ControlNbr       INNER JOIN t_PCD_Claimant ON t_DATA_Reclamation.ClaimantCode = t_PCD_Claimant.ClaimantCode     ORDER BY t_DATA_CashiersChecksIssued.Audit_DateAdded DESC

答案 1 :(得分:0)

使用 TOP n SQL语法:

if EXISTS ( /* Look for an unprinted check - "date_issued is null" */ )
   /* print unprinted checks */
ELSE
   select top 1 /* already-printed-checks  */
   where .... "date_issued is not null"

OR

当你这样做时,你想要打印“空白/取消”检查吗?

答案 2 :(得分:0)

您必须决定如何选择“至少一个”。

最简单的方法(可能)是删除WHERE子句中排除已打印支票的条件。我们假设是t_DATA_CashiersChecksIssued.DateIssued IS NULL。现在在SELECT子句中添加一列,如下所示:CASE WHEN t_DATA_CashiersChecksIssued.DateIssued IS NULL then 0 ELSE 1 END并在ORDER BY子句中首先创建该列。

现在在该过程中,只从该游标中获取一行。如果这个新列的值为0,那么至少要处理一个新的检查,你应该遍历游标,但是当你到达已经发布的那个时停止。如果它的值为1,则没有新的检查。

编辑:另一种方法是在SQL中正确执行。保留原文,但添加如下子句: UNION ALL SELECT ... AND ROWNUM = 1其中...代表您现有的查询,但条件是排除已打印的支票已删除。再想一想,这可能更简单。