Query shows greater value of duration in trace than when the query is run by itself Query shows greater value of duration in trace than when the query is run by itself database database

Query shows greater value of duration in trace than when the query is run by itself


how larger? you know that in profiler the duration is stored in microseconds, right? So 1000000 means 1 second.

Besides that, you need to take into considerations other things like reuse of execution plan or even the fact that SSMS is an UI tool and may be doing something else with your query before sending it to the database, and profiler gets the statistics directly from the execution on the DB, which can explain a few seconds more on the execution


Is the version your profiling part of an SP that is generated dynamically?

e.g.

..@sql = 'select * from ' + @tablenameexec (@sql)

Most SPs are pre-compiled after their first execution but SPs with non-static code such as the snippet above would never become pre-compiled. But if in the query window you were running

select * from the_table_name

This might show the difference you're seeing. Bit of a guess though I'm afraid. Maybe you can tell us more about how the query is run, if it is part of an SP etc.