# Related Sites > SQL Course >  Same SQL query produces two different results

## jjkatz

This is a strange one.  I have a stored procedure that determines a count of the number of records that meet certain criteria.  If I call the stored procedure in a Query Analyzer window by using "exec sp_[procedurename]" I get a count of 1.  If I copy the SQL from the stored procedure, paste it into the Query Analyzer window and run it, I get a count of 0.  The 0 value is correct.

There is no rounding involved in the query.  In a general sense, can anyone explain why the same exact query on the same database would return two different results?

----------


## rmiao

Hard to tell without reading code, but did you compare execution plan?

----------


## jjkatz

I'm not much good at reading those but I do see some differences.  I've attached both.  "SP" is the plan generated when calling the SP by name.  "Query" is the plan generated by running the code in a QA window.

In general, why would a stored procedure execute differently if called by name than if you run the code in a QA window?

----------


## rmiao

You can get graphic plan, easier to read. By the way, look like have different plans.

----------


## jjkatz

Yes, that's what is so strange.  It's the same code!  The only difference between the two is that in one case I am executing the stored procedure by calling it; in the other I pasted all the code from the SP into a QA window and ran it that way.

----------


## rmiao

Update statistics on tables then try again.

----------


## jjkatz

I was about to do that when the issue appeared to resolve itself.  I'll have to watch and see if it happens again, then try your suggestion.  Thanks (again) for your help!

----------

