﻿<?xml version="1.0" encoding="utf-8"?>
<BusinessFunctions>
  <BusinessFunction>
    <FunctionName>Concatenate 3 fields</FunctionName>
    <Type>SQL</Type>
    <FunctionDescription>Use the SQL Snippet in transformation to concatenate three  fields with a space. </FunctionDescription>
    <FunctionParameter>
      <ParameterName>[Field 1]</ParameterName>
      <ParameterType>Field</ParameterType>
      <ParameterDecription />
      <ParameterOrdinal>0</ParameterOrdinal>
    </FunctionParameter>
    <FunctionParameter>
      <ParameterName>[Field 2]</ParameterName>
      <ParameterType>Field</ParameterType>
      <ParameterDecription />
      <ParameterOrdinal>1</ParameterOrdinal>
    </FunctionParameter>
    <FunctionParameter>
      <ParameterName>[Field 3]</ParameterName>
      <ParameterType>Field</ParameterType>
      <ParameterDecription />
      <ParameterOrdinal>2</ParameterOrdinal>
    </FunctionParameter>
    <LibraryPath>Concatenate</LibraryPath>
    <Formular>[Field 1] + ' ' + [Field 2] + ' ' + [Field 3]</Formular>
  </BusinessFunction>
  <BusinessFunction>
    <FunctionName>Concatenate 2 fields</FunctionName>
    <Type>SQL</Type>
    <FunctionDescription>Use the SQL Snippet in transformation to concatenate two fields with a space. </FunctionDescription>
    <FunctionParameter>
      <ParameterName>[Field 1]</ParameterName>
      <ParameterType>Field</ParameterType>
      <ParameterDecription>This is the 1st field before the space.</ParameterDecription>
      <ParameterOrdinal>0</ParameterOrdinal>
    </FunctionParameter>
    <FunctionParameter>
      <ParameterName>[Field 2]</ParameterName>
      <ParameterType>Field</ParameterType>
      <ParameterDecription>This is the 2nd field after the space.</ParameterDecription>
      <ParameterOrdinal>1</ParameterOrdinal>
    </FunctionParameter>
    <LibraryPath>Concatenate</LibraryPath>
    <Formular>[Field 1] + ' ' + [Field 2]</Formular>
  </BusinessFunction>
  <BusinessFunction>
    <FunctionName>Time Table</FunctionName>
    <Type>SQL</Type>
    <FunctionDescription>This SQL Snippet should be used in a script action in order to populate a 24 hour time table with 15 minute increments.
In order for this script to work, you must first create a dimTime table with the following fields: StartTime(DateTime), EndTime(DateTime), Hour(Int), Minutes(Int), HourText(Varchar), MinuteText(Varchar)</FunctionDescription>
    <FunctionParameter>
      <ParameterName>[dimTime]</ParameterName>
      <ParameterType>Table</ParameterType>
      <ParameterDecription />
      <ParameterOrdinal>0</ParameterOrdinal>
    </FunctionParameter>
    <FunctionParameter>
      <ParameterName>[StartTime]</ParameterName>
      <ParameterType>Field</ParameterType>
      <ParameterDecription>Data Type DateTime</ParameterDecription>
      <ParameterOrdinal>1</ParameterOrdinal>
    </FunctionParameter>
    <FunctionParameter>
      <ParameterName>[EndTime]</ParameterName>
      <ParameterType>Field</ParameterType>
      <ParameterDecription>Data Type DateTime</ParameterDecription>
      <ParameterOrdinal>2</ParameterOrdinal>
    </FunctionParameter>
    <FunctionParameter>
      <ParameterName>[Hour]</ParameterName>
      <ParameterType>Field</ParameterType>
      <ParameterDecription>Data Type Int</ParameterDecription>
      <ParameterOrdinal>3</ParameterOrdinal>
    </FunctionParameter>
    <FunctionParameter>
      <ParameterName>[Minute]</ParameterName>
      <ParameterType>Field</ParameterType>
      <ParameterDecription>Data Type Int</ParameterDecription>
      <ParameterOrdinal>4</ParameterOrdinal>
    </FunctionParameter>
    <FunctionParameter>
      <ParameterName>[HourText]</ParameterName>
      <ParameterType>Field</ParameterType>
      <ParameterDecription>Data Type Varchar</ParameterDecription>
      <ParameterOrdinal>5</ParameterOrdinal>
    </FunctionParameter>
    <FunctionParameter>
      <ParameterName>[MinuteText]</ParameterName>
      <ParameterType>Field</ParameterType>
      <ParameterDecription>Data Type Varchar</ParameterDecription>
      <ParameterOrdinal>6</ParameterOrdinal>
    </FunctionParameter>
    <LibraryPath>Date and time</LibraryPath>
    <Formular>--Script written by TimeXtender NA; Tobias Eld, Joseph Treadwell

DECLARE @counter datetime
SET @counter = 0
WHILE @counter &lt;'1900-01-02 00:00:00.000'

BEGIN
  INSERT INTO [dimTime]([StartTime], [EndTime], [Hour], [Minute])
  VALUES (@counter,dateadd(MINUTE,15,@counter),DATEPART(HOUR,@counter),datepart(MI,@counter))

  SET @counter =  dateadd(MI,15,@counter)
END

UPDATE [dimTime]
SET 
	[HourText] = left(right(convert(nvarchar,dateadd(HH, [Hour], CAST(0 as datetime)),20),8),5),
	[MinuteText] = left(right(convert(nvarchar,dateadd(HH, [Hour], dateadd(mi,[Minute],CAST(0 as datetime))),20),8),5) +' - '+ left(right(convert(nvarchar,dateadd(HH, [Hour], dateadd(mi,[Minute]+14,CAST(0 as datetime))),20),8),5)</Formular>
  </BusinessFunction>
  <BusinessFunction>
    <FunctionName>Last date of month</FunctionName>
    <Type>SQL</Type>
    <FunctionDescription>Returns a datetime value containing the last date of the month based on a datetime value in a field</FunctionDescription>
    <FunctionParameter>
      <ParameterName>DateParam</ParameterName>
      <ParameterType>Field</ParameterType>
      <ParameterDecription />
      <ParameterOrdinal>0</ParameterOrdinal>
    </FunctionParameter>
    <LibraryPath>Date and time</LibraryPath>
    <Formular>DATEADD (d, -1, DATEADD (mm, DATEDIFF (m, 0, DateParam) + 1, 0))</Formular>
  </BusinessFunction>
  <BusinessFunction>
    <FunctionName>First date of year</FunctionName>
    <Type>SQL</Type>
    <FunctionDescription>Returns a datetime value containing the first date of the year based on the datetime value of a field</FunctionDescription>
    <FunctionParameter>
      <ParameterName>DateParam</ParameterName>
      <ParameterType>Field</ParameterType>
      <ParameterDecription />
      <ParameterOrdinal>0</ParameterOrdinal>
    </FunctionParameter>
    <LibraryPath>Date and time</LibraryPath>
    <Formular>DATEADD (yy, DATEDIFF (yy, 0, DateParam), 0) </Formular>
  </BusinessFunction>
  <BusinessFunction>
    <FunctionName>First date of previous year</FunctionName>
    <Type>SQL</Type>
    <FunctionDescription>Returns a datetime value containing the first date of a prevoius year

Enter 1 for last year. The value entered determines the number of years to go back.</FunctionDescription>
    <FunctionParameter>
      <ParameterName>DateParam</ParameterName>
      <ParameterType>Field</ParameterType>
      <ParameterDecription />
      <ParameterOrdinal>0</ParameterOrdinal>
    </FunctionParameter>
    <FunctionParameter>
      <ParameterName>YearDistance</ParameterName>
      <ParameterType>Value</ParameterType>
      <ParameterDecription />
      <ParameterOrdinal>1</ParameterOrdinal>
    </FunctionParameter>
    <LibraryPath>Date and time</LibraryPath>
    <Formular>DATEADD (yy, DATEDIFF (yy, 0, DateParam) - YearDistance, 0)</Formular>
  </BusinessFunction>
  <BusinessFunction>
    <FunctionName>First date of next year</FunctionName>
    <Type>SQL</Type>
    <FunctionDescription>Returns a datetime value containing the first date of next year</FunctionDescription>
    <FunctionParameter>
      <ParameterName>DateParam</ParameterName>
      <ParameterType>Field</ParameterType>
      <ParameterDecription />
      <ParameterOrdinal>0</ParameterOrdinal>
    </FunctionParameter>
    <LibraryPath>Date and time</LibraryPath>
    <Formular>DATEADD (yy, DATEDIFF (yy, 0, DateParam) + 1, 0)</Formular>
  </BusinessFunction>
  <BusinessFunction>
    <FunctionName>First date of month</FunctionName>
    <Type>SQL</Type>
    <FunctionDescription>Returns a datetime value containing the first date of the month based on a datetime value in a field</FunctionDescription>
    <FunctionParameter>
      <ParameterName>DateParam</ParameterName>
      <ParameterType>Field</ParameterType>
      <ParameterDecription />
      <ParameterOrdinal>0</ParameterOrdinal>
    </FunctionParameter>
    <LibraryPath>Date and time</LibraryPath>
    <Formular>DATEADD (mm, DATEDIFF (mm, 0, DateParam), 0)</Formular>
  </BusinessFunction>
  <BusinessFunction>
    <FunctionName>First date of last year</FunctionName>
    <Type>SQL</Type>
    <FunctionDescription>Returns a datetime value containing the first date of last year</FunctionDescription>
    <FunctionParameter>
      <ParameterName>DateParam</ParameterName>
      <ParameterType>Field</ParameterType>
      <ParameterDecription />
      <ParameterOrdinal>0</ParameterOrdinal>
    </FunctionParameter>
    <LibraryPath>Date and time</LibraryPath>
    <Formular>DATEADD (yy, DATEDIFF (yy, 0, DateParam) - 1, 0)</Formular>
  </BusinessFunction>
  <BusinessFunction>
    <FunctionName>First date of future year</FunctionName>
    <Type>SQL</Type>
    <FunctionDescription>Returns a datetime value containing the first date of future year

Enter 1 for next year. The value entered determines the number of years to go forward.</FunctionDescription>
    <FunctionParameter>
      <ParameterName>DateParam</ParameterName>
      <ParameterType>Field</ParameterType>
      <ParameterDecription />
      <ParameterOrdinal>0</ParameterOrdinal>
    </FunctionParameter>
    <FunctionParameter>
      <ParameterName>YearDistance</ParameterName>
      <ParameterType>Value</ParameterType>
      <ParameterDecription />
      <ParameterOrdinal>1</ParameterOrdinal>
    </FunctionParameter>
    <LibraryPath>Date and time</LibraryPath>
    <Formular>DATEADD (yy, DATEDIFF (yy, 0, DateParam) + YearDistance, 0)</Formular>
  </BusinessFunction>
  <BusinessFunction>
    <FunctionName>DateKey</FunctionName>
    <Type>SQL</Type>
    <FunctionDescription>Converts a datetime value to an integer to be used as a date dimension key.	</FunctionDescription>
    <FunctionParameter>
      <ParameterName>DateValue</ParameterName>
      <ParameterType>Field</ParameterType>
      <ParameterDecription>This is the date field you wish to convert.</ParameterDecription>
      <ParameterOrdinal>0</ParameterOrdinal>
    </FunctionParameter>
    <LibraryPath>Date and time</LibraryPath>
    <Formular>Convert(varchar,DateValue,112)</Formular>
  </BusinessFunction>
  <BusinessFunction>
    <FunctionName>DateDiff (Variable End Date)</FunctionName>
    <Type>SQL</Type>
    <FunctionDescription>Returns the number of date and time boundaries crossed between two specified dates.

Datepart
year: yy, yyyy
quarter: qq, q
month: mm, m
dayofyear: dy, y
day: dd, d
week: wk, ww
Hour: hh
minute: mi, n
second: ss, s
millisecond: ms

</FunctionDescription>
    <FunctionParameter>
      <ParameterName>datepart</ParameterName>
      <ParameterType>Value</ParameterType>
      <ParameterDecription>DatePart See Snippet Description for options</ParameterDecription>
      <ParameterOrdinal>0</ParameterOrdinal>
    </FunctionParameter>
    <FunctionParameter>
      <ParameterName>startdate</ParameterName>
      <ParameterType>Field</ParameterType>
      <ParameterDecription>Starting Date - Must be a DateTime field type</ParameterDecription>
      <ParameterOrdinal>1</ParameterOrdinal>
    </FunctionParameter>
    <FunctionParameter>
      <ParameterName>enddate</ParameterName>
      <ParameterType>Field</ParameterType>
      <ParameterDecription>Ending Date - Must be a DateTime field Type</ParameterDecription>
      <ParameterOrdinal>2</ParameterOrdinal>
    </FunctionParameter>
    <LibraryPath>Date and time</LibraryPath>
    <Formular>DATEDIFF(datepart,startdate,enddate)</Formular>
  </BusinessFunction>
  <BusinessFunction>
    <FunctionName>DateDiff (Fixed End date)</FunctionName>
    <Type>SQL</Type>
    <FunctionDescription>Returns the number of date and time boundaries crossed between two specified dates.

Datepart
year: yy, yyyy
quarter: qq, q
month: mm, m
dayofyear: dy, y
day: dd, d
week: wk, ww
Hour: hh
minute: mi, n
second: ss, s
millisecond: ms

</FunctionDescription>
    <FunctionParameter>
      <ParameterName>datepart</ParameterName>
      <ParameterType>Value</ParameterType>
      <ParameterDecription>DatePart Parameter, See Snippet description for options</ParameterDecription>
      <ParameterOrdinal>0</ParameterOrdinal>
    </FunctionParameter>
    <FunctionParameter>
      <ParameterName>startdate</ParameterName>
      <ParameterType>Field</ParameterType>
      <ParameterDecription>Starting Date - Must be a DateTime field Type</ParameterDecription>
      <ParameterOrdinal>1</ParameterOrdinal>
    </FunctionParameter>
    <LibraryPath>Date and time</LibraryPath>
    <Formular>DATEDIFF(datepart,startdate,GetDate())</Formular>
  </BusinessFunction>
  <BusinessFunction>
    <FunctionName>Current date - Last date of month</FunctionName>
    <Type>SQL</Type>
    <FunctionDescription>Returns a datetime value containing the last date of the month based on the current datetim</FunctionDescription>
    <LibraryPath>Date and time</LibraryPath>
    <Formular>DATEADD (d, -1, DATEADD (mm, DATEDIFF (m, 0, GETDATE ()) + 1, 0))</Formular>
  </BusinessFunction>
  <BusinessFunction>
    <FunctionName>Current date - First date of year</FunctionName>
    <Type>SQL</Type>
    <FunctionDescription>Returns a datetime value containing the first date of the year based on the current datetime</FunctionDescription>
    <LibraryPath>Date and time</LibraryPath>
    <Formular>DATEADD (yy, DATEDIFF (yy, 0, getdate ()), 0) </Formular>
  </BusinessFunction>
  <BusinessFunction>
    <FunctionName>Current date - First date of previous year</FunctionName>
    <Type>SQL</Type>
    <FunctionDescription>Returns a datetime value containing the first date of a prevoius year

Enter 1 for last year. The value entered determines the number of years to go back.</FunctionDescription>
    <FunctionParameter>
      <ParameterName>YearDistance</ParameterName>
      <ParameterType>Value</ParameterType>
      <ParameterDecription />
      <ParameterOrdinal>0</ParameterOrdinal>
    </FunctionParameter>
    <LibraryPath>Date and time</LibraryPath>
    <Formular>DATEADD (yy, DATEDIFF (yy, 0, getdate ()) - YearDistance, 0)</Formular>
  </BusinessFunction>
  <BusinessFunction>
    <FunctionName>Current date - First date of next year</FunctionName>
    <Type>SQL</Type>
    <FunctionDescription>Returns a datetime value containing the first date of next year</FunctionDescription>
    <LibraryPath>Date and time</LibraryPath>
    <Formular>DATEADD (yy, DATEDIFF (yy, 0, getdate ()) + 1, 0)</Formular>
  </BusinessFunction>
  <BusinessFunction>
    <FunctionName>Current date - First date of month</FunctionName>
    <Type>SQL</Type>
    <FunctionDescription>Returns a datetime value containing the first date of the month based on the current datetime</FunctionDescription>
    <LibraryPath>Date and time</LibraryPath>
    <Formular>DATEADD (mm, DATEDIFF (mm, 0, GetDate ()), 0) </Formular>
  </BusinessFunction>
  <BusinessFunction>
    <FunctionName>Current date - First date of last year</FunctionName>
    <Type>SQL</Type>
    <FunctionDescription>Returns a datetime value containing the first date of last year</FunctionDescription>
    <LibraryPath>Date and time</LibraryPath>
    <Formular>DATEADD (yy, DATEDIFF (yy, 0, getdate ()) - 1, 0)</Formular>
  </BusinessFunction>
  <BusinessFunction>
    <FunctionName>Current date - First date of future year</FunctionName>
    <Type>SQL</Type>
    <FunctionDescription>Returns a datetime value containing the first date of a future year

Enter 1 for next year. The value entered determines the number of years to go forward.</FunctionDescription>
    <FunctionParameter>
      <ParameterName>YearDistance</ParameterName>
      <ParameterType>Value</ParameterType>
      <ParameterDecription />
      <ParameterOrdinal>0</ParameterOrdinal>
    </FunctionParameter>
    <LibraryPath>Date and time</LibraryPath>
    <Formular>DATEADD (yy, DATEDIFF (yy, 0, getdate ()) + YearDistance, 0)</Formular>
  </BusinessFunction>
  <BusinessFunction>
    <FunctionName>Extract NavCompany</FunctionName>
    <Type>SQL</Type>
    <FunctionDescription />
    <FunctionParameter>
      <ParameterName>[Source Table]</ParameterName>
      <ParameterType>Field</ParameterType>
      <ParameterDecription />
      <ParameterOrdinal>0</ParameterOrdinal>
    </FunctionParameter>
    <LibraryPath>Dynamics &amp; Navision</LibraryPath>
    <Formular>REPLACE(SUBSTRING([Source Table], CHARINDEX('.', [Source Table])+1, CHARINDEX('$', [Source Table])-CHARINDEX('.', [Source Table])-1), '_', '.')</Formular>
  </BusinessFunction>
  <BusinessFunction>
    <FunctionName>Split Right</FunctionName>
    <Type>SQL</Type>
    <FunctionDescription />
    <FunctionParameter>
      <ParameterName>[ValueToSplit]</ParameterName>
      <ParameterType>Field</ParameterType>
      <ParameterDecription />
      <ParameterOrdinal>0</ParameterOrdinal>
    </FunctionParameter>
    <LibraryPath>Split</LibraryPath>
    <Formular>SUBSTRING([ValueToSplit],CHARINDEX(' ',[ValueToSplit]),50)</Formular>
  </BusinessFunction>
  <BusinessFunction>
    <FunctionName>Split Left</FunctionName>
    <Type>SQL</Type>
    <FunctionDescription />
    <FunctionParameter>
      <ParameterName>[ValueToSplit]</ParameterName>
      <ParameterType>Field</ParameterType>
      <ParameterDecription />
      <ParameterOrdinal>0</ParameterOrdinal>
    </FunctionParameter>
    <LibraryPath>Split</LibraryPath>
    <Formular>SUBSTRING([ValueToSplit],1,CHARINDEX(' ',[ValueToSplit]))</Formular>
  </BusinessFunction>
</BusinessFunctions>