SQL Server Performance

@@SPID of calling procedure?

Discussion in 'SQL Server 2008 General Developer Questions' started by dmanter, Nov 19, 2009.

  1. dmanter New Member

    Is there a way to get the @@SPID who called a stored procedure.
    i.e. SPID #59 calls stored procedure SP_MYProc which then has its own SPID #60. Can the Proc know #59 called it and use #59 as a key to some temp table. This way the proc can write data private to each of the callers.
  2. Madhivanan Moderator

    Like this
    Create procedure proc_1
    declare @spid int
    set @spid=@@spid

    EXEC proc_2 parameters,@spid

    This way you can pass the spid of calling procedure proc_1 to called procedure proc_2
  3. Adriaan New Member

    If proc1 calls proc2, they'll have the same @@spid ...

Share This Page