Stored procedure:
EXEC
or EXECUTE
statement.OUT
parameter.Function:
Can only be used to select records. However, it can be called very easily from within standard SQL, such as:
SELECT dbo.functionname('Parameter1')
or
SELECT Name, dbo.Functionname('Parameter1') FROM sysObjects
For simple reusable select operations, functions can simplify code.
Just be wary of using JOIN
clauses in your functions. If your
function has a JOIN
clause and you call it from another select
statement that returns multiple results, that function call will JOIN
those tables together for each line returned in the result set. So
though they can be helpful in simplifying some logic, they can also be a
performance bottleneck if they're not used properly.
OUT
parameter.