Friday, June 30, 2017

Tip of the Day: Variables and Type Cast Processing in R:BASE
Product.......: R:BASE X and R:BASE X Enterprise (Version 10)
Build.........: 10.0.2.20530 or higher
Section.......: Commands
Keywords......: Data Type, Variable, Expression, SELECT, SET VAR

Did you know R:BASE uses a "specific sequence" in expression processing in
order to determine a data type?

At times, variables are passed without an explicit data type, so R:BASE uses
a sequence to guess the actual type.

The sequence order is as follows:

01. INTEGER
02. DOUBLE
03. CURRENCY
04. DATE
05. TIME
06. DATETIME
07. BOOLEAN

If you define a variable using SET VAR, without first defining its type, it
will be assigned a type based on whether it can be interpreted as one of the
data types in this list. If not, the variable will be assigned as text.

Consider the following commands:

SET VAR v1 = '6/29/2017'
SET VAR v2 = '6-29-2017'
SET VAR v3 = '6.29.2017'
SET VAR v4 = '6#29#2017'

All four variables will end up with DATE as the data type because R:BASE can
interpret each one as a valid date.

When creating views with variables in the SELECT command, the expression
processing must also be considered.

In the following example, a SerialID column is added to the view definition
with a TEXT variable assigned for the value.

  SET VAR vSerialID TEXT = '1.1.1'
  CREATE TEMPORARY VIEW `EmpNetSales` +
    (EmpID,EmpFName,EmpLName,NetAount,SerialID) +
    AS SELECT  +
    T1.EmpID, T1.EmpFName, T1.EmpLName, T2.NetAmount,.vSerialID +
    FROM Employee T1, SalesByEmployee T2 +
    WHERE T1.EmpID = T2.EmpID

However, using a just dotted variable makes the SELECT command equivalent to
having typed in: '1.1.1'

Just like the above "SET VAR" examples, this too will result in a DATE value
because it is a valid input format for the date 1/1/2001.

The solution is to simply add parenthesis around the dotted variable!

  SET VAR vSerialID TEXT = '1.1.1'
  CREATE TEMPORARY VIEW `EmpNetSales` +
    (EmpID,EmpFName,EmpLName,NetAount,SerialID) +
    AS SELECT  +
    T1.EmpID, T1.EmpFName, T1.EmpLName, T2.NetAmount,(.vSerialID) +
    FROM Employee T1, SalesByEmployee T2 +
    WHERE T1.EmpID = T2.EmpID

In order for R:BASE's expression processing to explicitly see the variable with
its TEXT data type, it must be enclosed in parenthesis. Without the parenthesis,
the data type is unknown.

The rule of thumb is:

When you have a value that must be preserved as TEXT, and its possible the value can be interpreted as a different data type, enclosed the variable in parenthesis.

One of the most important aspects in business growth is your company data, and no one else has more invested in your success than R:BASE Technologies. Invest forward
with R:BASE!

Very Best R:egards,

Razzak.

www.rbase.com
www.facebook.com/rbase
--

--
You received this message because you are subscribed to the Google Groups 
"RBASE-L" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to