SQL server is occasionally returning hours to weeks old data using both SSMS and application connections. The problem persists long enough for me to verify the problem in both applications and SSMS as well as run slightly altered queries that return the latest data. This is happening across multiple tables in the database. But seems to be isolated to a few rows at a time. NOTE: There is 1 ROW per itemnumber ie the nonclustered index.
SELECT tableA.itemnumber, tableA.location, tableB.itemtype
from tableA left join tableB on tableA.itemnumber=tableB.itemnumber
where tableA.warehouse = @warehouse and tableA.itemnumber in (@item1, @item2, ...)
but if I select from tableA
directly or with a different query joined to more tables then both SSMS and applications return the 1 ROW of current data. Also I confirmed this behavior using snapshot isolation, no isolation, and even nolock
running under different users.
I'd like to understand how this can happen and possible ways to resolve this issue.
The database is originally from our ERP.
All the tables are heaps (no clustered index).
Running on 2012 SQL Server.
Implements snapshot but not RCSI.
Indexes are supposedly rebuilt each week (but cannot confirm, I have seen the index fragmentation at 90).
The errors occur maybe 10 times / 10,000 a day but it's difficult to track since data constantly changes in these tables throughout the day. For now I'm cross-referencing 2 queries and when they don't match, I throw an error and say to try later.