select

Execute SQL statement select or exec (call) and return result for first row in an object

 

Execute select command and return a value or  object with property value1,value2...valuex

 

Note

This command is  faster as execute

 

Syntax

object=SQLStatement.[select command];
object=SQLStatement.select("[select command]");
object=SQLStatement.select(select command);

 

Example:

let myResult=SQLStatement.select "FrgnName","ItemName" from "OITM" where "ItemCode"='RM';
alert(myResult.value1);

or

 

let myResult=SQLStatement.select(
   {
    select "FrgnName","ItemName" from "OITM" where "ItemCode"='RM');
   }
  );
alert(myResult.ItemName);

 

Working with INTO command

with command "into" you can define the name of properties of created object

let myResult=SQLStatement.select "FrgnName","ItemName"  into fname,iname from "OITM" where "ItemCode"='RM';
alert(myResult.fname+" "+myResult.iname);

 

 

Short variant is "sql"

let myResult=sql.select "FrgnName","ItemName" from "OITM" where "ItemCode"='RM';
alert(myResult.ItemName);

 

Working with arguments:

 

Arguments are defined with double point

The system convert the argument to sql compatible string related to the data type of the Argument

 

let a="RM";

let resultObject=SQLStatement.select "FrgnName","ItemName" from "OITM" where "ItemCode"=:a;

alert(resultObject.value1+" "+resultObject.value2);

 
function calls  are allowed: ... "ItemCode"=:myFunction(a);
point notations are allowed: ... "ItemCode"=:a.upperCase();

Formulas in bracket allowed: ... "ItemCode"=:('XX'+a.left(30))

 

Conversion

Data Type

Result

String

HANA: "String" MSQL: N"String"

DateTime

"yyyy/mm/dd hh:mm:ss"

Number

1000.10  (always Point)

 

Note: if data type of argument not same as the SQL field data type, this produce an sql error

 

This produce an SQL Error, because ItemCode is string and argument is a number

let a=10;
sql.select "ItemName" from "OITM" where "ItemCode"=:a; // ERROR!

This working fine.

let a=10;
sql.select "ItemName" from "OITM" where "ItemCode"=:String(a); // OK