Alex Rivera | Logout

Function vs. Stored Procedure in SQL Server

Asked 2009-07-24T19:40:06.827
1028

When should I use a function rather than a stored procedure in SQL, and vice versa? What is the purpose of each?

Edit
Report

2 Answers

59

Write a user-defined function when you want to compute and return a value for use in other SQL statements; write a stored procedure when you want instead is to group a possibly-complex set of SQL statements. These are two pretty different use cases, after all!

answered 2009-07-24T19:42:36.743
6

To decide on when to use what the following points might help-

  1. Stored procedures can't return a table variable where as function can do that.

  2. You can use stored procedures to alter the server environment parameters where as using functions you can't.

cheers

answered 2009-07-24T19:54:50.087

Your Answer