Query formulas are a powerful tool for SIS exports and data integration, making it possible to export your data in precisely the format and layout required by external systems. Query Formula Export Parts can be used to:

- perform mathematical calculations
- combine multiple fields into one export column
- write if/then statements

and otherwise manipulate data in the Query Builder.

# Adding a Formula

# Common Functions

## Mathematical Operations

Most mathematical functions can be done using a formula. The data type must be compatible with the operation you are performing. When in doubt, use the data type of *real*.

#### Examples

@merit_aid + @fafsa_aid

@tuition - @merit_aid

@merit_aid * 4.0

@total_merit_aid / 4.0

## Case Statement

Returns different results based on certain conditions, like an 'if...then...' statement. It goes through the conditions in order and will return the result for the first condition met. If no conditions are met, the END result will be returned. If there is no END result, a null value will be returned.

#### Syntax

case

whencondition1thenresult1whencondition2thenresult2

whenconditionNthenresultN

elseresult3end

#### Example

case @person_student_type

when 'TFR' then 'This is a transfer'

when 'GRD' then 'This is a graduate'

else 'This is a first-year'

end

## Coalesce

Returns the first non-null value in a series of values.

#### Syntax

coalesce(@value1, @value2, @valueN)

#### Example

coalesce(@application_program, @person_program)

## Convert

Changes the data type of a stored value for the export or filter. Data types that can be used:

- date
- datetime
- int (integer)
- money
- real
- string (characters)

This can be useful if you are hoping to perform mathematical functions on values that may not be stored as real numbers or integers. Most data types can be altered by double-clicking on the export and changing the 'Format Type.'

#### Syntax

try_convert(data_type,@value)

#### Example

try_convert(varchar(max), @record_guid)

## Date Addition

Adds a unit of time, using various units:

- minute
- hour
- day
- month
- year

to a date and then returns the new date. Negative interval values can be used to subtract a time from a specified date as well.

#### Syntax

dateadd(time_unit, interval_value, @value)

#### Example

dateadd(day, 4, @application_created_date)

## Date Difference

Subtracts Value 1 from Value 2 in various units of time: minute, hour, day, month, year. If you want to calculate Age, use the standard Person exports of 'Age (as of date)' and 'Current Age Based on Birthdate.'

#### Syntax

datediff(time_unit, @value1, @value2)

#### Example

datediff(day, @application_created_date, @application_submitted_date)

## Like

Searches a value to see if it contains certain characters or numbers. Wildcards '%' can represent zero, one, or multiple variable characters.

#### Syntax

@valueLIKE 'pattern'

@valueLIKE'%pattern'

@valueLIKE'pattern%'

#### Examples

@person_last LIKE 'Johnson'

@person_email LIKE '%@technolutions.com'

## Null If

Returns Value 1 if the values are not equal or returns a null value if they are equal. Can be used to avoid a mathematical error if dividing, and the denominator could be 0.

#### Syntax

nullif(@value1, @value2)

#### Example

@email_interactions / nullif(@total_interactions, 0)