Examples: SQL_GetConnection()


The following example is a portion of the metric processing script for a Home Page metric. It uses the SQL_GetConnection() function to retrieve a pass-through SQL connection that is used to access data for the metric.

local string sDbName;
local long SQL_connection;
local long SQL_status;
local text SQL_Statements;

{Retrieve the current company's database}
sDbName = 'Intercompany ID' of globals;

if 'SQL Server' of globals > 0 then
	SQL_status = SQL_GetConnection(FOREGROUND, SQL_connection) of form XSQLExec;
	if SQL_status = OKAY then
		{Build SQL statement to use the appropriate database.}
		SQL_Statements = "use " + sDbName;
	
		{Execute the SQL statements.}
		SQL_status = SQL_Execute(SQL_connection, SQL_Statements);
	end if;

	SQL_Statements = "select top 5 LeadName, PotentialRevenue from IG001 order by PotentialRevenue desc";
	{Execute the SQL statements.}
	SQL_status = SQL_Execute(SQL_connection, SQL_Statements);
end if;


Documentation Feedback