3

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).

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
  • 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 – Leo Aug 30 '16 at 05:06
  • 1
    Simple, one of the main reasons is you cant call the result set of Stored procedure inside a select column statement. – timblistic Aug 30 '16 at 05: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. – RBT Aug 30 '16 at 05:16
  • A procedure can not return a scalar value, e.g. `where some_column = some_function(other_column)` –  Aug 30 '16 at 05:37
  • "*My understanding is that stored procedures works faster than functions*" - that understanding is wrong. –  Aug 30 '16 at 05:37

1 Answers1

2

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

Racil Hilan
  • 24,690
  • 13
  • 50
  • 55