4

Please don't specify the differences between stored procedure and functions. Just want the reasons where functions have an advantage over stored procedures.

My understanding is that stored procedures works faster than functions and it can do all that a function can do so why do we need function in place?

I have read articles where it states that it can easily embedded in an select statement but that can be done in stored procedure as well (by writing the whole select statement in the stored procedure).

5
  • The most common case-scenario to use a function is if yo need to do some "processing" inside a select statement...sprocs can't be used here Commented Aug 30, 2016 at 5:06
  • 1
    Simple, one of the main reasons is you cant call the result set of Stored procedure inside a select column statement. Commented Aug 30, 2016 at 5:06
  • Function calls like GETDATE can be used even in the definition of computed columns of SQL Server or as default values. Using a stored procedure is simply not a possibility in such cases. Commented Aug 30, 2016 at 5:16
  • A procedure can not return a scalar value, e.g. where some_column = some_function(other_column) Commented Aug 30, 2016 at 5:37
  • "My understanding is that stored procedures works faster than functions" - that understanding is wrong. Commented Aug 30, 2016 at 5:37

1 Answer 1

2

A function can be used inline in SQL statements while stored procedures cannot.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.