This gives me the result This is giving me result like Individually it gives me count as 1 but when executed inside stored procedure it give me 0. SO how do I implement this inside the procedure? Please note some time there may not be any result set in the 'finished' block that is why I am using please suggest..
(comments are locked)
|
|
Firstly COALESCE wont be affecting how many rows are returned, it will simply apply its effort on whatever rows there are. I think you may need to review the value of @MID as that appears in the WHERE clause in the procedure but does not have any code to avoid it being NULL. If it is NULL then your result set could be empty. Try replacing with
(comments are locked)
|
|
The advice from Jonathan Allen is excellent but I would restate it as if "@MID" paramater would be NULL, then the whole dynamic SQL will become NULL.... There should be a section to validate the NULL values for @MID and @Year. Also, I do not see anything wrong with the execution if it is returning 0's for no results. But if it is the problem with a same parameter, then debug it by printing the dynamic sql. This is the first basic step to troubleshoot the dynamic sql.
(comments are locked)
|


I am not sure what is the problem here? If there would be no results sets then count should be zero as given? Can you please post some test data, desired output and the wrong output according to the data?
And you do not have to use COALESCE as the output would already be shown as zero with the COUNT.
If I am not using COALESCE then I am not getting that rows even there is a empty set. Like FINISHED In Time 0 will not come if I do not add COALESCE function
OK I have revisited your code it has more working than the problem you described like the years string, PIVOT etc. So there might be some problem in there. Without having some test data and with such least information about the exact problem, it is pretty difficult to help.