Sql Query takes too long in stored proc

Found this issue when a stored procedure was taking it too long to execute and the same query inside the proc took fraction of a second. Never seen this before did some searching and found a simple fix. Add option (recompile) at the end of the query and voila problem resolved.

Advertisements