Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 IF statement not good idea in TSQL

Author  Topic 

spatemp
Starting Member

11 Posts

Posted - 2010-05-24 : 22:12:00
College of mine tells me that IF statement in stored procedure is not a good idea becuase:

1) it either recompiles stored proc on every use
2) or the sql statement inside the "if" are not cached etc...

Is any of this true. Anoterword, is there any downside in using IF statement in SQL stored proc.

Thanks for your help.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-05-25 : 00:24:42
Your colleague is right in that a stored procedure can only have one execution plan, so multiple queries in a stored procedure could cause a bad execution plan due to a not frequently used path. In a situation where you'll have multiple queries you should put them into their own stored procedures.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

zstarsales04
Starting Member

20 Posts

Posted - 2010-05-25 : 02:11:40
spam removed
Go to Top of Page
   

- Advertisement -