sql查询问题,操纵数据

时间:2009-12-02 02:47:46

标签: sql sql-server sql-server-2005

我有存储过程,告诉我们是否有新的支票要打印。现在我必须操纵数据库表中的数据才能至少打印一张支票。我没有写这个查询。我试过但是我没有至少打印一张支票。谁能帮我。这是存储的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

GO

`

1 个答案:

答案 0 :(得分:0)

假设表中有数据,这将更新第一行。

UPDATE TOP(1) t_DATA_CashiersChecksIssued
   SET SerialMbr = NULL,
       DataIssued = NULL
  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