if( this.USE_DATE_IN_SUBQUERY ) subqueryDefn.addResultSetExpression("sub4", new ScriptExpression("dataSetRow.SALE_DATE"));
	private QueryDefinition newPreIVReportQuery( int filterNeeded,			boolean sortNeeded, int groupNeeded, int mode )	{		QueryDefinition qd = new QueryDefinition( );				// add basic column binding		IBaseExpression[] rowBeArray = getRowExpr( );		IBaseExpression[] totalBeArray = getAggrExpr( );		for ( int i = 0; i < rowBeArray.length; i++ )			qd.addResultSetExpression( this.rowExprName[i], rowBeArray[i] );		for ( int i = 0; i < totalBeArray.length; i++ )			qd.addResultSetExpression( this.totalExprName[i], totalBeArray[i] );				if ( this.updateNewBindingName != null && this.updateNewBindingName.trim( ).length( ) > 0 )		{			qd.addResultSetExpression( this.updateNewBindingName, this.updateNewBindingExpr );		}				if ( mode == UPDATE )		{			qd.getFilters( ).addAll( this.GEN_filterDefn );		}		else if ( mode == PRESENTATION )		{			if ( PRE_basedon_genfilter == false )				qd.getFilters( ).addAll( UPDATE_filterDefn );			else				qd.getFilters( ).addAll( GEN_filterDefn );		}				if ( filterNeeded == 0 )		{			// do filtering on column 4			ScriptExpression filterExpr = new ScriptExpression( "row.AMOUNT_1>200" );			FilterDefinition fd = new FilterDefinition( filterExpr );			qd.addFilter( fd );		}		if ( filterNeeded == 1 )		{			ScriptExpression filterExpr = new ScriptExpression( "row.AMOUNT_1>50" );			FilterDefinition fd = new FilterDefinition( filterExpr );			qd.addFilter( fd );						filterExpr = new ScriptExpression( "row.AMOUNT_1<7000" );			fd = new FilterDefinition( filterExpr );			qd.addFilter( fd );		}		if ( filterNeeded == 2 )		{			ScriptExpression filterExpr = new ScriptExpression( "row.AMOUNT_1>50" );			FilterDefinition fd = new FilterDefinition( filterExpr );			qd.addFilter( fd );						filterExpr = new ScriptExpression( "row.AMOUNT_1<700" );			fd = new FilterDefinition( filterExpr );			qd.addFilter( fd );		}				if ( filterNeeded == 3 )		{			ScriptExpression filterExpr = new ScriptExpression( "row.AMOUNT_1>200" );			FilterDefinition fd = new FilterDefinition( filterExpr );			qd.addFilter( fd );						filterExpr = new ScriptExpression( "row.COUNTRY_1==\"US\"" );			fd = new FilterDefinition( filterExpr );			qd.addFilter( fd );		}		//filter on date		if ( filterNeeded == 4 )		{			BaseExpression filterExpr = new ConditionalExpression( 					"row.SALE_NAME_1", IConditionalExpression.OP_EQ,					"\"2004-01-01 00:00:00+"+TimeZone.getDefault( ).getRawOffset( )/3600000+"\"" );			FilterDefinition fd = new FilterDefinition( filterExpr );			qd.addFilter( fd );		}				//TopN filter		if ( filterNeeded == 5 )		{			ConditionalExpression filterExpr = new ConditionalExpression( "row.AMOUNT_1", IConditionalExpression.OP_TOP_N,"3" );			FilterDefinition fd = new FilterDefinition( filterExpr );			qd.addFilter( fd );		}				UPDATE_filterDefn = qd.getFilters( );		if ( sortNeeded )		{			// do sorting on column 4			SortDefinition sd = new SortDefinition( );			sd.setExpression( "row.AMOUNT_1" );			sd.setSortDirection( ISortDefinition.SORT_ASC);			qd.addSort( sd );		}		if ( groupNeeded == 1 || groupNeeded == 0 )		{			GroupDefinition gd = null;			if ( groupNeeded == 1 )			{				gd = new GroupDefinition( "Agroup" );				gd.setKeyColumn( "AMOUNT_1" );				qd.addGroup( gd );			}			else if ( groupNeeded == 0 )			{				// add grouping on column1				gd = new GroupDefinition( );				gd.setKeyColumn( "COUNTRY_1" );				qd.addGroup( gd );			}			if ( this.UPDATE_add_subquery == 1 )			{				SubqueryDefinition subqueryDefn = new SubqueryDefinition( subQueryName1 );				subRowExprName1 = new String[3];				subRowExprName1[0] = "sub1";				subRowExprName1[1] = "sub2";				subRowExprName1[2] = "sub3";				ScriptExpression[] exprs = new ScriptExpression[3];				exprs[0] = new ScriptExpression( "dataSetRow.COUNTRY" );				exprs[1] = new ScriptExpression( "dataSetRow.CITY" );				exprs[2] = new ScriptExpression( "dataSetRow.AMOUNT" );				for ( int i = 0; i < subRowExprName1.length; i++ )					subqueryDefn.addResultSetExpression( subRowExprName1[i],							exprs[i] );				subqueryDefn.setApplyOnGroupFlag( true );				gd.addSubquery( subqueryDefn );			}						if ( this.UPDATE_add_subquery == 2 )			{				SubqueryDefinition subqueryDefn = new SubqueryDefinition( subQueryName2 );				subRowExprName2 = new String[2];				subRowExprName2[0] = "sub1";				subRowExprName2[1] = "sub2";				ScriptExpression[] exprs = new ScriptExpression[2];				exprs[0] = new ScriptExpression( "dataSetRow.COUNTRY" );				exprs[1] = new ScriptExpression( "dataSetRow.CITY" );				for ( int i = 0; i < subRowExprName2.length; i++ )					subqueryDefn.addResultSetExpression( subRowExprName2[i],							exprs[i] );				subqueryDefn.setApplyOnGroupFlag( true );				gd.addSubquery( subqueryDefn );			}		}				return qd;	}