Some query values change when query is run but not others. Why?

  • Hi everyone

    I have a 1000 line SQL query that is too long to put here so I will explain the basic logic and what the issue is.

    The query processes stock market data and produces a daily metric for each symbol.  There are close to 4000 symbols that get the metric created daily. I am testing the query and I am seeing some odd behaviour.  For most symbols, if the query is re-run using the same data the metrics for the day do not change.  This is expected.  However, for some symbols, each time the query is run the metric is completely different for the SAME data.  This is definitely not expected.  If all the values changed each time I ran the query for the SAME data then I understand that something is clearly wrong.  However, for some symbols the metric keeps changing each time I run the query on the SAME data but others do not change.  The ones that don't change are producing the correct value.  I am truly stumped.  There is no symbol-specific logic in the query (ie, no hard-coding logic that applies different logic to a particular symbol).  Instead, it is just "select symbol from .... where ... etc"  I have no clue where to even begin.  It is helpful to have the query to look at to provide helpful feedback so I apologize in advance for the inconvenience from not seeing the query.  I am hoping members on this forum can provide some suggestions on what to look for as part of the investigation.  I will investigate whatever feedback I get.

    Thank you

  • Is there an order by? You can have duplicates and sql may pick a random duplicate without order by

  • Do you have a TOP(n) without an ORDER BY?

    Is it always the same symbols that are static, and the same symbols that change?

    With such a large query, I would start by trying to focus on specific symbols, and also cutting out as much of the query as possible to return the absolute minimum.  Then slowly add back parts of the query until things start to change.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply