Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I currently run a sql statement like so:

SELECT TOP 400 * 

FROM Stage.tblCustomer 


I notice that if I run it i get say: 58 results. If I run it again immediately after I may get 58 or I may get 62. The general pattern is that if I keep executing the statement, it eventually hits 400.

What would cause this to happen? I am not changing server or database connections and have not altered the sql in any way. I've brought this up to our DW Chief and was disregarded. I suspect a load may be taking place as the DB is updated every 30 minutes.

What I have tried:

Asked "experts" and google searched for relevant examples.
Posted
Updated 16-Jul-21 10:24am
Comments
Tomas Takac 8-Jun-16 19:07pm    
The only explanation is that something is inserting records into that table. Try to run sp_who2 stored procedure to see what is going on. Or run a trace.
CHill60 9-Jun-16 6:44am    
Could depend on the Isolation level used - see Understanding Isolation Levels[^]

1 solution

You did not use "Order By" clause. So every time, that you execute the query, SQL will order on its own decision.
 
Share this answer
 
Comments
Richard Deeming 19-Jul-21 6:16am    
Irrelevant. If there were at least 400 rows, then 400 rows would be returned every time. If there were less, then all rows would be returned every time.

As Tomas mentioned in the comments back in 2016, the only explanation is that another process is inserting data into the table in between executions of the SELECT query.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900