How to get name of the executing script

  • This might be a very silly question. How can I get name of the script which is getting executed.

    I have about 2000 scripts which I need to execute using a tool which will take these scripts as a batch job.

    I want to print name of the script before it starts its main function and again print its name once it is done

    Thanks in advance for any help

  • SELECT OBJECT_NAME(@@PROCID);

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • That just give me NULL

  • It depends on the context that it's running under. If you're running it in a query window, it probably will return NULL.

    Try this:

    CREATE PROCEDURE ProcName

    AS

    SELECT OBJECT_NAME(@@PROCID);

    GO

    EXEC [ProcName];

    You should see 'ProcName' in the result set.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply