The amount of email I receive sometime it is impossible for me to answer every email. Nonetheless I try to answer pretty much every email I receive. However, quite often I receive such questions in email that I have no answer to them because either emails are not complete or they are out of my domain expertise. In recent times I received one email which had only one or two lines but indeed attracted my attention to it. The question was bit vague but it indeed made me think. The answer was not straightforward so I had to keep on writing the answer as I remember it. However, after writing the answer I do not feel satisfied. Let me put this question in front of you and see if we all can come up with a comprehensive answer.
Question: I am beginner with SQL Server. I have one query, it sometime returns a result and sometime it does not return me the result. Where should I start looking for a solution and what kind of information I should send to you so you can help me with solving. I have no clue, please guide me.
Well, if you read the question, it is indeed incomplete and it does not contain much of the information at all. I decided to help him and here is the answer, which I started to compose.
Answer: As there are not much information in the original question, I am not confident what will solve your problem. However, here are the few things which you can try to look at and see if that solves your problem.
- Check parameter which is passed to the query. Is the parameter changing at various executions?
- Check connection string – is there some kind of logic around it?
- Do you have a non-deterministic component in your query logic? (In other words – does your result is based on current date time or any other time based function?)
- Are you facing time out while running your query?
- Is there any error in error log?
- What is the business logic in your query?
- Do you have all the valid permissions to all the objects used in the query? Are permissions changing or query accessing a different object in various executions?
- (Add your suggestions here)
Meanwhile, have you ever faced this situation? If yes, do share your experience in the comment area. I will send a copy of my book SQL Server Interview Questions and Answers to one of the most interesting comment. The winner will be announced by next Monday.
Reference: Pinal Dave (http://blog.sqlauthority.com)