Why did the Print Statement in T-SQL solve my reporting issue?
I have a complex report running in T-SQL, which in query analyzer was running fine but whenever I ran it off the web it was getting timed out. So there I am trying to figure out what is going on and start debugging with print statements before and after each call. The problem is solved! Now the website is loading the report faster than it has ever loaded it and all I did was add print '1', print'2', and so on around each select nothing else. I haven't changed a line of 开发者_开发技巧code otherwise. I take those print statements out the code blows up again. Because of the print statements I know why I was getting the error. There was a NULL value in one of my aggregates. I still haven't fixed the data problem. I am confused as to why this has solved my problem, any thoughts?
If this is a long running query the chances are that you are reaching a timeout period as Varuuknahl has said.
Adding print statements would reset the timeout and your query would be given more time to return the main result set.
I suggest you either simplfy the query if possible, there are many people on this site who could help you with that or you could increase the timeout period in your web application which is calling this procedure/report to run.
If you want someone to fix the aggregated NULL problem you have, let us see the query and we can give some advice.
精彩评论