I have a database in SQL Server 2008 with 2 tables. I'm running the following query on Management Studio:
select M.FD_BROWSER_SHORT_NAME AS X, Count(1) AS Y
from TB_EVENTS E
INNER JOIN TB_MACHINES M ON E.FD_ID = M.FD_ID AND E.FD_ID_NET = M.FD_ID_NET
where E.FD_EVENT_CODE = 30
group by M.FD_BROWSER_SHORT_NAME
having Count(1) > 10
When I run this query, the results are:
X Y
OP 23
CR 1809
IE 5392
MZ 1000
Then I run the query again (F5), on the same database (same session). The result changes to:
X Y
OP 1023
CR 1809
IE 5392
When I run the query again the result back to normal:
X Y
OP 23
CR 1809
IE 5392
MZ 1000
On the same server, at same time, I have a C# application changing the database (INSERTs and UPDATEs). When I stop this application, the problem stops.
First, I thought the problem was related to locks. Then I tried to add this before the SQL statement:
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
But the problem keeps ocurring.
I tried to reproduce the problem in another server, but it don't occurs. I tried to migrated the database to another server and another version of SQL Server and it still occurs.
The problem occurs with another queries containing aggregation functions.
I also tried to update the statistics and rebuild all the indexes. Nothing...
Any ideas?