QA returning inconsistent records

Here's perhaps the most bizarre thing I've seen from SQL Server in a long time. I have two tables, TiMaster (1.2million recs) and Staff (300 recs) and an application that gets inconsistent results. So I ran the sql statements directly in Query Analyzer and found differing results, from time to time.

Is there something wrong with my statement syntax? The only thing I can think of is the "T.STAFF IN (..." part of the Where clause might not handle strings the way I expect. I've used it consistently with a set of integers, but maybe 'AS' would be treated as found in a list containing 'ASX'?

This one returns consistently a set of records for user 'VT' which total 1,151 hours. But when I add more users, with everything else identical, the number of records returned is FEWER (sometimes)! They usually, but not always, return 296 hours. Another bizarre twist here is that if I keep the number of STAFF items in the list the same, but shorten the date range, the correct number of hours are returned.

That sounded like the perfect solution. Perfectly explains the differing results, and also explains why I could import all that data into a new database and NOT see different results. However, after the reindex, I still get the same problem.

I'm not giving up on the idea of corrupted indices, though. Unfortunately, I've got about 80 users in the system for another 5-6 hours, but after that I'm planning to do a complete rebuild of the tables and indices.

Would the index rebuild be invalidated / delayed if there are clients using the tables? The response from QA indicated that the rebuild was complete, but didn't mention anything about errors.

Sorry for the long delay here. I tried all of the above, including DBCC CHECKDB. None of that had any effect. The indices and tables reported no errors.

However, here's what worked. In the Where clause, when I changed "(T.STAFF IN ('ASB', ..." to "(S.STAFF_ID IN ('ASB', ...", it worked perfectly. I'm clueless as to why, though. I'm still willing to award the points to whomever can tell me why. I thought specifying the staff criteria on the TiMaster table would be more appropriate (that's the detail of all time records). The STAFF table is, obviously, one record per staff member. You'll see one of the criteria in the Where clause is (T.STAFF = S.STAFF_ID).

Two questions: 1. Why would my change make such a difference? and, 2. Is there a difference in how that type of statement was implemented in different versions of SQL Server? (Remember, my copy of their data worked every time. I'm on SQL 2000 and my client is probably on SQL Server 7.0.)

Featured Post

At Springboard, we know how to get you a job in data science. With Springboard’s Data Science Career Track, you’ll master data science with a curriculum built by industry experts. You’ll work on real projects, and get 1-on-1 mentorship from a data scientist.