Search Results

Search found 2 results on 1 pages for 'jeffself'.

Page 1/1 | 1 

  • Need help tuning a SQL statement

    - by jeffself
    I've got a table that has two fields (custno and custno2) that need to be searched from a query. I didn't design this table, so don't scream at me. :-) I need to find all records where either the custno or custno2 matches the value returned from a query on the same table based on a titleno. In other words, the user types in 1234 for the titleno. My query searches the table to find the custno associated with the titleno. It also looks for the custno2 for that titleno. Then it needs to do a search on the same table for all other records that have either the custno or custno2 returned in the previous search in the custno or custno2 fields for those other records. Here is what I've come up with: SELECT BILLYR, BILLNO, TITLENO, VINID, TAXPAID, DUEDATE, DATEPIF, PROPDESC FROM TRCDBA.BILLSPAID WHERE CUSTNO IN (select custno from trcdba.billspaid where titleno = '1234' union select custno2 from trcdba.billspaid where titleno = '1234' and custno2 != '') OR CUSTNO2 IN (select custno from trcdba.billspaid where titleno = '1234' union select custno2 from trcdba.billspaid where titleno = '1234' and custno2 != '') The query takes about 5-10 seconds to return data. Can it be rewritten to work faster?

    Read the article

  • Need to speed up the results of this SQL statement. Any advice?

    - by jeffself
    I've got the following SQL Statement that needs some major speed up. The problem is I need to search on two fields, where each of them is calling several sub-selects. Is there a way to join the two fields together so I call the sub-selects only once? SELECT billyr, billno, propacct, vinid, taxpaid, duedate, datepif, propdesc FROM trcdba.billspaid WHERE date(datepif) > '01/06/2009' AND date(datepif) <= '01/06/2010' AND custno in (select custno from cwdba.txpytaxid where taxpayerno in (select taxpayerno from cwdba.txpyaccts where accountno in (select accountno from rtadba.reasacct where controlno = 1234567))) OR custno2 in (select custno from cwdba.txpytaxid where taxpayerno in (select taxpayerno from cwdba.txpyaccts where accountno in (select accountno from rtadba.reasacct where controlno = 1234567)))

    Read the article

1