EXECUTE

Execute a stored procedure or function.

Syntax
 stored procedure or function

      [EXEC[UTE]
         { 
           [@return_status = ]
              {module [;number ] | @module_name_var } 
                [[@parameter = ]
                   {value 
                   | @variable [ OUTPUT ] 
                   | [ DEFAULT ] 
                   }
           ]
             [ ,...n ] [ WITH RECOMPILE ]
         } [;]

Character string
     EXEC[UTE] 
        ( { @string_variable | [ N ]'tsql_string' } [ + ...n ] )
           [ AS { LOGIN | USER } = ' name ' ] [;]

Pass-through command (linked server)
     EXEC[UTE]
        ( { @string_variable | [ N ] 'command_string [ ? ] ' } [ + ...n ]
           [ { , { value | @variable [ OUTPUT ] } } [ ...n ] ]
        ) 
        [AS { LOGIN | USER } = 'name' ]
           [AT linked_server_name ] [;]

Key:
    return_status    Return status of a module (integer variable) 
    number           int. used to group procedures (optional, deprecated )
    module_name_var  locally defined variable 
    value            If parameter names are not specified, values must be supplied
                     (in the order defined in the module.)
    OUTPUT           The module or command string returns a parameter.
    DEFAULT          The default value of the parameter as defined in the module. 
    name             A valid sysadmin user/login name.  (not a built-in account)

Example

-- run procedure passing '5' as a parameter value
EXEC dbo.MyProcedure 5;
GO -- run procedure passing 'ABC764' as a parameter value EXEC Sales.GetPartsOfType @PartCode = N'ABC764'; GO

“The villainy you teach me, I will execute, and it shall go hard but I will better the instruction” ~ Shakespeare (The Merchant of Venice)

Related:

EXECUTE AS
Equivalent Oracle command: EXECUTE


© Copyright SS64.com 1999-2014
Some rights reserved