5 The DB2 Data Provider : Using Global Variables

Using Global Variables
For DB2 V9.5 and higher for Linux/UNIX/Windows, the DB2 data provider supports global variables. You can access and modify these named memory variables through SQL statements. Using global variables lets you share data between different SQL statements running in the same session (or connection) without writing application code to transfer the data.
For example, the following C# code snippet creates a global variable to identify the printer to use during the session:
DB2Command cmd = new DB2Command();
cmd.CommandText= "CREATE VARIABLE TEST01.MYJOB_PRINTER VARCHAR(30) DEFAULT 'Default printer'";
cmd.ExecuteNonQuery();
cmd.CommandText = "SELECT MYJOB_PRINTER FROM SYSIBM.SYSDUMMY1";
DataReader reader = cmd.ExecuteReader();
 
while (reader.Read()) {
     Console.WriteLine(reader.GetString(1));
}
 
cmd.CommandText = "SET MYJOB_PRINTER = 'New Printer 1'");
cmd.ExceuteNonQuery();
 
cmd.CommandText = "SELECT MYJOB_PRINTER FROM SYSIBM.SYSDUMMY1");
while (reader.Read()) {
     Console.WriteLine(reader.GetString(1));
}
For more information about using global variables, refer to your DB2 documentation.