How to Define Global Variable

  • How can we set Session specific Global Variable in SQL SERVER 2005.

    Is there any concept of Global Variables?

    I know about the Global Temp table. I am more concern for Global Variables.

    Immediate response will be highly appreciated.

    Regards

    Chandrashekhar

  • There is, in fact, a mechanism to do what you need (though it is not in the most convenient format ever):  Session Context information.  To quote from BoL:

    Session context information enables applications to set binary values of up to 128 bytes that can be referenced in multiple batches, stored procedures, triggers, or user-defined functions operating on the same session. You can set a session context value by using the SET CONTEXT_INFO statement and retrieve it by using one of the following:

    • The CONTEXT_INFO function.
    • The context_info columns in the sys.dm_exec_requests and sys.dm_exec_sessions dynamic management views, and the sys.sysprocesses compatibility view.

    This is new, and something I didn't know before I went to try and answer your question.  Thanks - now we both know something new.

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

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