2012-10-14 81 views
2

我試圖運行此查詢,但它沒有返回任何內容。它將用戶輸入作爲變量獲取到查詢中。有一件事我不得不提到哪個是用戶離開batch_number s textbox empty, the query should return all the batches of the organization_ID`的時候。這裏是查詢:SQL查詢和取消變量

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'; 

回答

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它將返回true對於所有file_batch_number