AS SELECT DISTINCT Variables_1.VarID, 
StatementReference_1.bRead AS VariableReferenceType, 
StatementReference_2.ResourceType, 
StatementReference_2.ResourceID, 
StatementReference_2.bRead AS ResourceReferenceType, 
Statements.Description AS StatementType, 
OccurrencesStmt.StartRow, 
Paths.PathStr, 
ProgramAliases.AliasName AS ProgramName, 
ProgramTypes.ProgramType,
Programs.ProgramID,
OccurrencesStmt.OccurID
FROM ((((((
	StatementReference AS StatementReference_1 
	INNER JOIN Variables AS Variables_1 ON StatementReference_1.ResourceID = Variables_1.VarID) 
	INNER JOIN StatementReference AS StatementReference_2 ON StatementReference_1.OccurID = StatementReference_2.OccurID AND 
                 StatementReference_1.bRead <> StatementReference_2.bRead) 
	INNER JOIN Statements ON StatementReference_1.StatementType = Statements.StatementType) 
	INNER JOIN OccurrencesStmt ON StatementReference_1.OccurID = OccurrencesStmt.OccurID) 
	INNER JOIN Paths ON OccurrencesStmt.PathID = Paths.PathID) 
	INNER JOIN Programs ON OccurrencesStmt.ProgID = Programs.ProgramID
	INNER JOIN ProgramAliases ON Programs.ProgramID = ProgramAliases.ProgramId and ProgramAliases.AliasType = 0)  
	INNER JOIN ProgramTypes ON Programs.ProgramTypeID = ProgramTypes.ProgramTypeID
WHERE (
	((StatementReference_1.ResourceType)=4)
	AND ((StatementReference_2.ResourceType) In (1,6,9,18,19,20,21,56,61,62,69,70,77,78,81,182,189,190,193)) 
	AND (Variables_1.VarID IN (Select * from #numeric_param_temp)) 
	AND (StatementReference_2.bRead = 2)
	AND (StatementReference_1.bRead = 1) 
)
ORDER BY Variables_1.VarID