2

我正在尝试运行此查询,但它什么也没返回。它将用户输入作为查询的变量。我必须提到一件事,那就是用户何时离开batch_numbers textbox empty, the query should return all the batches of theorganization_ID`。这是查询:

SELECT Nvl(a.ORGANIZATION_ID, ' '), 
       Nvl(a.FILE_TYPE, ' '), 
       Nvl(a.BATCH_NUMBER, ' '), 
       Nvl(a.FILE_NAME, ' '), 
       Nvl(TOTAL_ANB_RECORDS, 0) 
FROM   PAYMENT B, 
       PAYROLL A 
WHERE  b.ORGANIZATION_ID = a.ORGANIZATION_ID 
       AND a.ORGANIZATION_ID = '1176' 
       AND PAYMENT_TYPE = '1' 
       AND Nvl(PAYMENT_STATUS, 'a') = '5' 
       AND ( BM_BATCH_INDC = '0' 
              OR BM_BATCH_INDC = '1' 
              OR BM_BATCH_INDC = '3' ) 
       AND b.FILE_TYPE = a.FILE_TYPE 
       AND b.FILE_BATCH_NUMBER = a.BATCH_NUMBER 
       AND ( b.FILE_BATCH_NUMBER = '"+textBox.text.ToString()+"' 
              OR b.FILE_BATCH_NUMBER IS NULL ) 
       AND b.PAYMENT_PATH = '01'; 
4

1 回答 1

0

假设它是空白数据,则为 NULL

写吧

AND b.FILE_BATCH_NUMBER = NVL(a.BATCH_NUMBER,b.FILE_BATCH_NUMBER)

代替

AND b.FILE_BATCH_NUMBER = a.BATCH_NUMBER 
       AND ( b.FILE_BATCH_NUMBER = '"+textBox.text.ToString()+"' 
              OR b.FILE_BATCH_NUMBER IS NULL )

如果 Batch_number 为 null,它将为所有 file_batch_number 返回 true

于 2012-10-16T18:54:37.253 回答