>How can one create a global variable in SQLSERVER? I would like to be able to create a global variable from within a procedure, and then have other procedures read the value of that variable, and take certain action on it. More specifically I would like to enable / disbale a trace_flag from withing a procedure and then based on the value of this flag, display a debugging message or not.
SQL Server does not support global variables. Could you create a control table for you application and write a row for your SPID. Then you could place whatever flags your application needs in there. Later, create a job that would remove rows for SPIDs that are no longer active.
HTH
-Mike