The best practices says that all your database related code should not be in the code behind or application layer. So all the SQL related code should be in the database and naturally inside the stored procedure.
However, sometimes if you have a very simple sql statement to execute and it is only static in nature you may write it in the C# (not in the code behind page but in different database layer - read this
http://www.dotnetfunda.com/articles/show/2708/3-tier-architecture-in-aspnet-a-complete-article).
If any of your C# method is executing more number of SQL statements from the database, preferably put all of them into stored procedure and execute once so that it executes fast.
The benefit of using stored procedure is that the execution plan of all the sql statement written there is prepared at the time of saving the stored procedure, the sql syntax is checked. So this makes the sql statement execution faster in comparison of executing them from the C# code.
The simple answer of your question is keep all sql statements in the database (stored procedure, udfs etc.).
Thanks
Regards,
Sheo Narayan
http://www.dotnetfunda.com
Vinoths09, if this helps please login to Mark As Answer. | Alert Moderator