Its a well known fact that the insert_recordset is used for performance reasons when we want to use set operations instead of doing record based loop and roundtrips to the server.
The only problem being that there is no type casting allowed. Consider a scenario like below where there is a data mismatch between the fields being inserted to and the fields being selected from:
In the statement below using the int2str function is not allowed so how do we type cast ?
Unfortunately there is no direct solution for the above using the statements, basically we would want to use a typecast function at the SQL level and this can only be done using views or direct sql statement. For this case we will try to create a view with the necessary type casting :insert_recordset PriorityTmp( PriortyCode, Description, OrderPlaningId, WrkCtrId, PriorityNum ) select "P" + int2str( PriorityNum) , "P" + int2str( PriorityNum ) , OrderPlaningId , WrkCtrId, PriorityNum from LocalOrderPlanning order PriorityNum asc where LocalOrderPlanning.RecId != orderPlanning.RecId && LocalOrderPlanning.WrkCtrId == orderPlanning.WrkCtrId && LocalOrderPlanning.PlanningStatus == OrderPlanning.PlanningStatus && LocalOrderPlanning.MergeLine == NoYes::NO;
static server str PriorityCode() { DictView dictView2; str sPriorityNumField, sReturnField; // Construct a DictView object for the present view. dictView2 = new DictView(tableNum(AFZOrderPlanningView)); // Get a string that has the target field name // propertly qualified with an alias (such as "A." or "B."). sPriorityNumField = dictView2.computedColumnString("AFZOrderPlanning", fieldStr(AFZOrderPlanning, PriorityNum ), FieldNameGenerationMode::FieldList, true); sReturnField = strFmt(" 'P' + cast( %1 as varchar)", sPriorityNumField); return sReturnField; }
No comments:
Post a Comment