Using and maintaining session variables or data within a user session in SQL Server is not so straightforward. With the SET CONTEXT_INFO statement, you can set a 128-bytes long binary value and you can read it with the CONTEXT_INFO function. However, having one single value within the scope of the session is a huge limitation. SQL Server 2017 brings more functionality for playing with session scope-related data.
The SESSION_CONTEXT function returns the value of the specified key in the current session context. This value was previously set using the sys.sp_set_session_context procedure. It accepts the nvarchar data type as an input parameter. Interestingly, the function returns a value with the sql_variant data type. ...