Expressions and Functions documentation

ENDUSER SOFTWARE LLC
DBX for GoldMine
Expressions
Library
Table of Contents
What are Expressions? ............................................................ 1
Custom Functions .................................................................... 3
ProperCase ..................................................................................... 3
StripPrefix ....................................................................................... 3
StripHtml ......................................................................................... 4
FormatAddress ............................................................................... 4
FormatCompany ............................................................................. 5
FormatContact ................................................................................ 5
FormatPhone .................................................................................. 6
FindAndReplace ............................................................................. 6
NormalizeString .............................................................................. 7
String Functions ....................................................................... 9
ASCII............................................................................................... 9
CHAR .............................................................................................. 9
CHARINDEX ................................................................................. 10
CONCAT ....................................................................................... 10
DIFFERENCE ............................................................................... 11
FORMAT ....................................................................................... 11
LEFT ............................................................................................. 12
LEN ............................................................................................... 12
LOWER/ UPPER .......................................................................... 13
LTRIM ........................................................................................... 13
PATINDEX .................................................................................... 14
REPLACE ..................................................................................... 15
REPLICATE .................................................................................. 15
REVERSE ..................................................................................... 16
RIGHT ........................................................................................... 16
RTRIM........................................................................................... 17
SPACE .......................................................................................... 17
STR ............................................................................................... 18
SUBSTRING ................................................................................. 18
Math Functions....................................................................... 19
ABS ............................................................................................... 19
CEILING........................................................................................ 19
FLOOR.......................................................................................... 20
ROUND ......................................................................................... 20
SQRT ............................................................................................ 21
SQUARE ....................................................................................... 21
Date Functions ....................................................................... 22
DATEADD ..................................................................................... 22
DATENAME .................................................................................. 23
E X P R E S S I O N S
L I B R A R Y
Intro
What are Expressions?
E
Xpressions contain a series of values and functions that can be used in DBX
for GoldMine to either evaluate, format, or set values. A common use of
expressions is in the Import Contact Data module where both field mappings
and match field items can use expressions.
Note
Please follow the instructions in the Applications Guide to install the DBX
Expressions Extended Pack. This module will allow users to access to the
Custom Expressions mentioned in this document.
For example, we can have the following field mapping:
Contact1.Key1 = Model
where Model is a field from an import table. However, we might need to always set
Model to upper case so we can do the following:
Contact1.Key1 = Upper(Model)
In the example above, Upper() is the function used in the expression “Upper(Model)”.
Note
An expression can contain a series of functions, pass a function as a
parameter to another function, or operate against different sets of data
values within the same expression.
DBX provides the following type of functions:

Custom Functions
1
E X P R E S S I O N S
L I B R A R Y

String Functions

Math Functions

Date Functions
2
E X P R E S S I O N S
1
Chapter
L I B R A R Y
Custom Functions
ProperCase
Description
Formats the first letter of each word to an upper case.
Syntax
ProperCase(string)
Arguments
string can contain a number of words
Return Type
string
Examples
ProperCase(‘dbx for GoldMine’) returns Dbx For Goldmine
StripPrefix
Description
Removes the first characters of a given string that matches
the search pattern.
Syntax
StripPrefix(param1,param2)
Arguments
Param1 is the string that is being operated on
Param2 is the search pattern
Return Type
string
Examples
StripPrefix(“Mr. John Doe”,”Mr.”) returns John Doe
3
E X P R E S S I O N S
L I B R A R Y
StripHtml
Description
Extracts the text from an html formatted string
Syntax
StipHtml(param1)
Arguments
Param1 is the string that contains the html formatted string
Return Type
string
Examples
StripHtml(“<b>Hello World</b>”) returns “Hello World”
FormatAddress
Description
Formats the address data.
Syntax
FormatAddress(param1,param2)
Arguments
Param1 contains the address string
Param2 will use the Normalization Address category items to
format certain keywords added to the Address normalization
dictionary. If this setting is set to false, the address data will
only be formatted to proper case.
Return Type
string
Examples
FormatAddress(“1 avenue of stars”,false) returns “1 Avenue
Of Stars”
4
E X P R E S S I O N S
L I B R A R Y
FormatCompany
Description
Formats the company data.
Syntax
FormatCompany(param1)
Arguments
Param1 contains the company string
Function will use the Normalization Company category
items to format certain keywords added to the company
normalization dictionary.
Return Type
string
Examples
FormatCompany(“enduser software, incorporated) returns
“EndUser Software, Inc.”
FormatContact
Description
Formats the contact data.
Syntax
FormatContact(param1)
Arguments
Param1 contains the contact string
Function will use the Normalization Contact category items
to format certain keywords added to the contact
normalization dictionary.
Return Type
string
Examples
FormatContact(“Antonio Banderas”) returns “Tony
Banderas”
This is assuming that the dictionary manager has “Antonio”
set as “Tony”.
5
E X P R E S S I O N S
L I B R A R Y
FormatPhone
Description
Formats the phone data.
Syntax
FormatPhone(param1)
Arguments
Param1 contains the phone number string
Return Type
string
Examples
FormatPhone(‘2134426546’) returns ‘(213)442-6546’
FormatPhone(‘+12132311142’) returns ‘+12132311142’
If the number is stripped from special characters and it is
equal to 10, then it will format it like ‘(xxx)xxx-xxxx’.
Otherwise, it will simply return the same input value.
FindAndReplace
Description
Performs a find/replace operation against a given
string
Syntax
FindAndReplace(param1,param2,param3)
Arguments
Param1 is the string that is being operated on
Param2 is the search pattern
Param3 is the value that will replace matched pattern
Return Type
string
Examples
FindAndReplace(“Mr. John Doe”,”Mr.”,”Mister”)
returns Mister John Doe
6
E X P R E S S I O N S
L I B R A R Y
NormalizeString
Description
Performs a find\replace operation based on a word
dictionary stored in the Normalization Dictionary.
Syntax
NormalizeString(param1,param2)
Arguments
Param1 is the string that is being operated on
Param2 is a flag indicating if special characters should
be removed.
0 = do not remove any special characters
1 = remove special characters, including spaces
2 = remove special characters, excluding spaces
Special Characters:
.,-_!@#$%^*()"=+[]{}|\<>`~'
Return Type
string
Examples
NormalizeString(“Mr. John-Henry Doe,1) returns
MisterJohnHenryDoe
*The example above assumes that you have added a dictionary
item for “Mr.” with an equivalent value of “Mister”.
7
E X P R E S S I O N S
L I B R A R Y
NormalizeStringByCategory
Description
Performs a find\replace operation based on a word
dictionary stored in the Normalization Dictionary,
but limiting its lookup based on a certain category
name.
Syntax
NormalizeStringByCategory(param1,param2,param3)
Arguments
Param1 is the category name
Param2 is the string that is being operated on
Param3 is a flag indicating if special characters should
be removed. Same as NormalizeString() function.
Return Type
string
Examples
NormalizeStringByCategory (“Titles”,“Mr. JohnHenry Doe”,1) returns MisterJohnHenryDoe
*The example above assumes that you have added a dictionary
item for “Mr.” with an equivalent value of “Mister” in a
dictionary category named “Titles”
8
E X P R E S S I O N S
2
Chapter
L I B R A R Y
String Functions
ASCII
Description
Returns the ASCII code value of the leftmost character of a
character expression.
Syntax
ASCII(character_value)
Arguments
Character_value is any letter or number
Return Type
integer
Examples
Ascii(‘D’) returns 68
Ascii(‘d’) returns 100
CHAR
Description
Converts an integer ASCII code to a character.
Syntax
CHAR(ascii_integer)
Arguments
Ascii_integer is an integer value that matches a character in
the Ascii table
Return Type
character
Examples
Char(78) returns ‘N’
Char(77) returns ‘M’
9
E X P R E S S I O N S
L I B R A R Y
CHARINDEX
Description
Searches an expression for another expression and returns
its starting position if found.
Syntax
CHARINDEX ( expressionToFind ,expressionToSearch [ ,
start_location ] )
Arguments
ExpressionToFind is a character expression that contains the
sequence to be found. expressionToFind is limited to 8000
characters.
expressionToSearch is a character expression to be searched.
start_location is an integer or bigint expression at which the
search starts. If start_location is not specified, is a negative
number, or is 0, the search starts at the beginning of
expressionToSearch.
Return Type
integer
Examples
CharIndex(‘GoldMine’,’DBX for GoldMine’) returns 9 since
the word ‘GoldMine’ starts at position 9.
CONCAT
Description
Returns a string that is the result of concatenating two or
more string values.
Syntax
CONCAT ( string_value1, string_value2 [, string_valueN ] )
Arguments
string_value is a string value to concatenate to the other
values.
Return Type
string
Examples
Concat(‘happy’,’ birthday ’,’to you’) returns ‘happy birthday
to you’
10
E X P R E S S I O N S
L I B R A R Y
DIFFERENCE
Description
Returns an integer value that indicates the difference
between the SOUNDEX values of two character
expressions.
The integer returned is the number of characters in the
SOUNDEX values that are the same. The return value
ranges from 0 through 4: 0 indicates weak or no similarity,
and 4 indicates strong similarity or the same values.
Syntax
DIFFERENCE ( string_expression , string_expression )
Arguments
string_expression is a string value
Return Type
integer
Examples
Difference(‘DBX 4 GoldMine’,’DBX for GoldMine’)
returns a 4 which means that they are very similar.
FORMAT
Description
Returns a value formatted with the specified format and
optional culture.
Syntax
FORMAT ( value, format )
Arguments
Value is a value of a supported data type to format.
Format is a string format pattern.
Follow the link below for more details:
http://msdn.microsoft.com/en-US/library/26etazsy.aspx
Return Type
string
Examples
Where current_date = 5/25/1975
Format(current_date,'d') returns “5/25/1975”
Format(current_date,'M') returns “May 25”
11
E X P R E S S I O N S
L I B R A R Y
LEFT
Description
Returns the left part of a character string with the specified
number of characters.
Syntax
LEFT ( character_expression , integer_expression )
Arguments
Character_expression is a string
Interger_expression is a positive integer that specified how
many characters will be returned.
Return Type
string
Examples
Left(‘DBX for GoldMine’,3) returns ‘DBX’
LEN
Description
Returns the number of characters of the specified string
expression, excluding trailing blanks.
Syntax
LEN ( string_expression )
Arguments
string_expression is the string expression to be evaluated.
string_expression can be a constant, variable, or column of
either character or binary data.
Return Type
int
Examples
Len(‘DBX’) returns 3
12
E X P R E S S I O N S
L I B R A R Y
LOWER/
UPPER
Description
Returns a character expression after converting uppercase
character data to lowercase.
Syntax
LOWER ( character_expression )
UPPER(character_expression)
Arguments
character_expression is an expression of character or binary
data. character_expression can be a constant, variable, or
column. character_expression must be of a data type that is
implicitly convertible to varchar. Otherwise, use CAST to
explicitly convert character_expression.
Return Type
string
Examples
Lower(“DBX”) returns “dbx”
Upper(“dbx”) returns “DBX”
LTRIM
Description
Returns a character expression after it removes leading
blanks.
Syntax
LTRIM ( character_expression )
Arguments
character_expression is an expression of character or
binary data. character_expression can be a constant, variable,
or column. character_expression must be of a data type,
except text, ntext, and image, that is implicitly convertible to
varchar. Otherwise, use CAST to explicitly convert
character_expression.
Return Type
string
Examples
LTrim(“
DBX”) returns “DBX”
13
E X P R E S S I O N S
L I B R A R Y
PATINDEX
Description
Returns the starting position of the first occurrence of a
pattern in a specified expression, or zeros if the pattern is
not found, on all valid text and character data types.
Syntax
PATINDEX ( '%pattern%' , expression )
Arguments
Pattern is a character expression that contains the sequence
to be found. Wildcard characters can be used; however, the
% character must come before and follow pattern (except
when you search for first or last characters). pattern is an
expression of the character string data type category. pattern
is limited to 8000 characters.
Expression is an expression, typically a column that is
searched for the specified pattern. expression is of the
character string data type category.
Return Type
int
Examples
PatIndex(“%for%”,”DBX for GoldMine”) returns 5
14
E X P R E S S I O N S
L I B R A R Y
REPLACE
Description
Replaces all occurrences of a specified string value with
another string value.
Syntax
REPLACE ( string_expression , string_pattern ,
string_replacement )
Arguments
string_expression is the string expression to be searched.
string_expression can be of a character or binary data type.
string_pattern is the substring to be found. string_pattern
can be of a character or binary data type. string_pattern
cannot be an empty string ('').
string_replacement
is
the
replacement
string.
string_replacement can be of a character or binary data type.
Return Type
string
Examples
Replace(‘DBX for GoldMine’,’for’,’4’)
returns ‘DBX 4 GoldMine’
REPLICATE
Description
Repeats a string value a specified number of times.
Syntax
REPLICATE ( string_expression ,integer_expression )
Arguments
string_expression is an expression of a character string or
binary data type. string_expression can be either character or
binary data..
integer_expression is an expression of any integer type,
including bigint. If integer_expression is negative, NULL is
returned.
Return Type
string
Examples
Replicate(‘0’,4) returns ‘0000’
15
E X P R E S S I O N S
L I B R A R Y
REVERSE
Description
Returns the reverse order of a string value.
Syntax
REVERSE ( string_expression )
Arguments
string_expression string_expression is an expression of a string
or binary data type. string_expression can be a constant,
variable, or column of either character or binary data.
Return Type
string
Examples
Reverse(‘abcdefg’) returns ‘gfedcba’
RIGHT
Description
Returns the right part of a character string with the specified
number of characters.
Syntax
RIGHT ( character_expression , integer_expression )
Arguments
character_expression is a string
integer_expression is the number of characters returned
from the right side
Return Type
String
Examples
Right(‘DBX for GoldMine’,8) returns ‘GoldMine’
16
E X P R E S S I O N S
L I B R A R Y
RTRIM
Description
Returns a character string after truncating all trailing blanks.
Syntax
RTRIM ( character_expression )
Arguments
Character_expression is an expression of character data.
character_expression can be a constant, variable, or column
of either character or binary data.
Return Type
String
Examples
Rtrim(‘This is a test
‘) returns ‘This is a test’
SPACE
Description
Returns a string of repeated spaces.
Syntax
SPACE ( integer_expression )
Arguments
integer_expression is a positive integer that indicates the
number of spaces. If integer_expression is negative, a null
string is returned.
Return Type
String
Examples
‘John’ + Space(2) + “Carter” returns “John Carter”
17
E X P R E S S I O N S
L I B R A R Y
STR
Description
Returns character data converted from numeric data.
Syntax
STR ( float_expression [ , length [ , decimal ] ] )
Arguments
float_expression is an expression of approximate numeric
(float) data type with a decimal point.
Length Is the total length. This includes decimal point,
sign, digits, and spaces. The default is 10.
Decimal is the number of places to the right of the decimal
point. decimal must be less than or equal to 16. If decimal is
more than 16 then the result is truncated to sixteen places to
the right of the decimal point.
Return Type
String
Examples
Str(123.45,6,1) returns 123.5
SUBSTRING
Description
Returns part of a text
Syntax
SUBSTRING ( expression ,start , length )
Arguments
Expression is a character, binary, text, ntext, or image
expression.
Start is an that specifies where the returned characters start
Length is a positive integer or bigint expression that
specifies how many characters of the expression will be
returned. If length is negative, an error is generated and the
statement is terminated. If the sum of start and len
Return Type
String
Examples
Substring(“DBX for GoldMine”,1,3) returns “DBX”
18
E X P R E S S I O N S
3
Chapter
L I B R A R Y
Math Functions
ABS
Description
A mathematical function that returns the absolute (positive)
value of the specified numeric expression.
Syntax
ABS ( numeric_expression )
Arguments
numeric_expression is a numeric value, positive or negative
Return Type
Returns the same type as numeric_expression
Examples
Abs(-1) returns 1
Abs(0.0) returns .0
Abs(4.0) returns 4.0
CEILING
Description
Returns the smallest integer greater than, or equal to, the
specified numeric expression.
Syntax
CEILING ( numeric_expression )
Arguments
numeric_expression is a numeric value, positive or negative
Return Type
Returns the same type as numeric_expression
Examples
Ceiling(32.45) returns 33.00
Ceiling(-23.90) returns -23.00
19
E X P R E S S I O N S
L I B R A R Y
FLOOR
Description
Returns the largest integer less than or equal to the specified
numeric expression.
Syntax
FLOOR ( numeric_expression )
Arguments
numeric_expression is a numeric value, positive or negative
Return Type
Returns the same type as numeric_expression
Examples
Floor(32.45) returns 32.00
Floor(-23.90) returns -24.00
ROUND
Description
Returns a numeric value, rounded to the specified length or
precision.
Syntax
ROUND ( numeric_expression , length )
Arguments
numeric_expression is an expression of the exact numeric
or approximate numeric data type category, except for the bit
data type.
Length is the precision to which numeric_expression is to
be rounded. length must be an expression of type tinyint,
smallint, or int. When length is a positive number,
numeric_expression is rounded to the number of decimal
positions specified by length. When length is a negative
number, numeric_expression is rounded on the left side of
the decimal point, as specified by length.
Return Type
Returns the same type as numeric_expression
Examples
Round(123.9994) returns 123.9990
Round(123.9995) returns 124.0000
20
E X P R E S S I O N S
L I B R A R Y
SQRT
Description
Returns the square root of the specified float value.
Syntax
SQRT ( float_expression )
Arguments
float_expression is an expression of type float or of a type
that can be implicitly converted to float.
Return Type
float
Examples
Sqrt(4) returns 2
Sqrt(81) returns 9
SQUARE
Description
Returns the square of the specified float value.
Syntax
SQUARE ( float_expression )
Arguments
float_expression is an expression of type float or of a type
that can be implicitly converted to float.
Return Type
float
Examples
Square(4) returns 16
Square(9) returns 81
21
E X P R E S S I O N S
4
Chapter
L I B R A R Y
Date Functions
DATEADD
Description
Returns a specified date with the specified number interval
(signed integer) added to a specified datepart of that date.
Syntax
DATEADD (datepart , number , date )
Arguments
Datepart is the part of date to which an integer number is
added. The following table lists all valid datepart arguments.
User-defined variable equivalents are not valid.
Valid Date Parts
year
quarter
month
dayofyear
day
week
weekday
hour
minute
second
millisecond
microsecond
nanosecond
Number is an expression that can be resolved to an int that
is added to a datepart of date. User-defined variables are valid.
22
E X P R E S S I O N S
L I B R A R Y
If you specify a value with a decimal fraction, the fraction is
truncated and not rounded.
Date is an expression that can be resolved to a time, date,
smalldatetime, datetime, datetime2, or datetimeoffset value.
date can be an expression, column expression, user-defined
variable, or string literal. If the expression is a string literal, it
must resolve to a datetime. To avoid ambiguity, use four-digit
years.
Return Type
date
Examples
DateAdd(year, 1, ‘2012-07-29’) returns 2013-07-29
DateAdd(year,-1,’2012-07-29’) returns 2011-07-29
DATENAME
Description
Returns a character string that represents the specified
datepart of the specified date
Syntax
DATENAME ( datepart , date )
Arguments
Datepart – same as DateAdd’s datepart parameter
date – a valid time,date, or datetime
Return Type
string
Examples
DateName(month,7/2/2012) returns July
DateName(DW,7/2/2012) returns Monday
23