You are on page 1of 4

Use of SQL Plus in Batch Plus Operating Instructions

In the examples shown below we concentrate in obtaining information from the Result
Database. This can be useful for instance to add to the operating instructions information
regarding equipment contents, streams or emissions.. This document assumes a basic
knowledge of SQL (Structured Query Language).

Introduction
For details in how to create and edit a Batch Plus Operating Instruction Templates see the
Online Help. To Use SQL Plus, edit a Batch Plus Operating Instructions Template (select
File->Preferences->Operating Instructions) and click Edit. From the Batch Plus menu in
Word, select Edit Standard Statement. In the standard statement template select the point
where you want to insert information from SQL Plus. Select SQL Plus from the Batch
Plus menu in Word. In the database dropdown select the database you want to query. All
the examples below use the Result Database. From the return data type select the type of
the return value (string, double or long). Notice that the query should return only one
field and its data type should be of the same type selected in the data type dropdown. As
explained below the query can return multiple records and therefore Batch Plus will
return multiple values, separated by commas, of the field used in the select query.

Examples
Contents of equipment units
The following query selects the mass of the liquid phase in the equipment unit at the end
of the current operation in the recipe. Notice the use of the keyword bpoperationid.
This indicates the operation id of the current operation in the recipe. This keyword is used
by Batch Plus to substitute the id of the operation being processed when generating the
operating instructions.
SELECT EquipmentContents.Mass*ThermodynamicPhase.MassPhaseFraction as dvalue
FROM ThermodynamicPhase INNER JOIN EquipmentContents ON
ThermodynamicPhase.ContentsID = EquipmentContents.ContentsID
WHERE ((ThermodynamicPhase.Phase="Liquid1") AND
(EquipmentContents.OperationID=bpoperationid))
The following query gets the names, separated by commas, of all the components in the
liquid phase of the equipment unit corresponding to the current operation in the recipe.
Notice again the key work bpoperationid
SELECT PureComponents.MaterialName as strvalue
FROM ((PhaseComponents INNER JOIN ThermodynamicPhase ON
PhaseComponents.PhaseID = ThermodynamicPhase.PhaseID) INNER JOIN
EquipmentContents ON ThermodynamicPhase.ContentsID =

EquipmentContents.ContentsID) INNER JOIN PureComponents ON


PhaseComponents.ComponentID = PureComponents.MaterialID
WHERE (((EquipmentContents.OperationID)=bpoperationid) AND
((ThermodynamicPhase.Phase)="Liquid1"))
Similar to the above query but it obtains the mass fractions, separated by commas, for all
the components in the liquid phase of the equipment unit associated with the current
operation in the recipe.
SELECT PhaseComponents.MassFraction as dvalue
FROM ((PhaseComponents INNER JOIN ThermodynamicPhase ON
PhaseComponents.PhaseID = ThermodynamicPhase.PhaseID) INNER JOIN
EquipmentContents ON ThermodynamicPhase.ContentsID =
EquipmentContents.ContentsID) INNER JOIN PureComponents ON
PhaseComponents.ComponentID = PureComponents.MaterialID
WHERE (((ThermodynamicPhase.Phase)="Liquid1") AND
((EquipmentContents.OperationID)=bpoperationid))
The queries can be combined to give the component and mole fraction by formatting the
SELECT statement as follows.
SELECT ([PureComponents].[MaterialName]+","+Format([PhaseComponents].
[MassFraction],"#. ###")) AS strvalue
FROM ((PhaseComponents INNER JOIN ThermodynamicPhase ON
PhaseComponents.PhaseID = ThermodynamicPhase.PhaseID) INNER JOIN
EquipmentContents ON ThermodynamicPhase.ContentsID =
EquipmentContents.ContentsID) INNER JOIN PureComponents ON
PhaseComponents.ComponentID = PureComponents.MaterialID
WHERE (((EquipmentContents.OperationID)=bpoperationid) AND
((ThermodynamicPhase.Phase)="Liquid1"))

Stream Information
To obtain the user-defined labels of all the streams associated with a given operation in
the recipe use the following query.
SELECT StreamSummary.UserLabel as strvalue
FROM StreamSummary
WHERE (((StreamSummary.OperationID)= bpoperationid))
As before this query will give the stream labels of all the streams associated with a given
operation separated by commas. The above query can be complemented by a query that
will give the mass or volumetric flow rate or any average property of the stream. For
instance, to obtain the volumetric flow rate use the following query.

SELECT StreamSummary.VolumetricFlowRate as dvalue


FROM StreamSummary
WHERE (((StreamSummary.OperationID)=bpoperationid))
As before all the volumetric flow rates will appear separated by commas. If you want to
combine the previous queries in one result, for instance to get the User Label = flow rate,
use the following query.
SELECT (IIF( [StreamSummary].UserLabel <> "", [StreamSummary].UserLabel + " = "
+ Format(StreamSummary.VolumetricFlowRate, ".##") + " " +
StreamSummary.VolumetricFlowRateUOM)) AS strvalue
FROM StreamSummary
WHERE ((([StreamSummary].OperationID)=bpoperationid))

Vapor Emission Flags/Warnings


Queries can be created to return a value if a condition exists. The query below returns
High Emission Operation for operations that contain an uncontrolled emissions over 10
kg. This type of query could also be used to include safety notes during hazardous
material charging.
SELECT IIf(Sum([AirEmissionSummary].[Mass])>10,"High Emission Operation","")
AS strvalue
FROM AirEmissionSummary
GROUP BY AirEmissionSummary.OperationID,
AirEmissionSummary.AirEmissionControl
HAVING (((AirEmissionSummary.OperationID)=bpoperationid) AND
((AirEmissionSummary.AirEmissionControl)="Uncontrolled Emission"));
With standard mass output specified in preferences as kg, this query will not return a
value unless uncontrolled emissions are greater than 10 kg.

Keywords

bpoperationid: Current operation ID

bptype: Text Recipe Type {"Operation", "Unit Procedure", "Series", "Start


Parallel", "End Parallel" "Start Or" or "End Or"}

bplabel: Text recipe label {1, 1.1, 1.2, 1.3, etc.}

bpoperationname: Batch Plus Operation Name See OperationsLibrary Table

bpunitprocedurename: User-Defined Unit procedure name when Type = Unit


Procedure;

bpoperationtypeid: Operation Type ID See OperationsLibrary Table

bprecipetext: Operation Recipe Text

bpusercomments: Operation Comment of Type selected in Tools\Options\Text


Recipe

bprangetext: Operation Range Text of Type selected in Tools\Options\Text Recipe

bpprimaryequipmentid: Primary Equipment ID of unit procedure (as defined in


the unit procedure dialog).

bpunitprocedurecomments: Unit Procedure Comment

bpstepid: ID number of current step

You might also like