Home Forums SQL Server 7,2000 T-SQL Difference between Stored procedure and functions RE: Difference between Stored procedure and functions

  • Vaiydeyanathan.V.S (10/31/2007)


    Functions

    ----------

    1) can be used with Select statement

    2) Not returning output parameter but returns Table variables

    3) You can join UDF

    4) Cannot be used to change server configuration

    It's more accurate to say it as: "cannot be used to change ANYTHING". Functions in SQL are not allowed to have any kind of permanent effect, so they can't modify ANYTHING permanent. The only thing they're allowed to change would be a table variable created within the function itself.

    5) Cannot be used with XML FOR clause

    Not true. It's all in how you use it.

    6) Cannot have transaction within function

    If you can't modify anything - there's no point in allowing transactions.....

    Stored Procedure

    -----------------

    1) have to use EXEC or EXECUTE

    2) return output parameter

    3) can create table but won’t return Table Variables

    4) you can not join SP

    You can't join to it DIRECTLY. You can use some 4easy techniques to join to it (OPENQUERY for one thing).

    5) can be used to change server configuration

    6) can be used with XML FOR Clause

    7) can have transaction within SP

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?