RIGHT (SSIS)

Returns the part of a character expression that begins at and is to the right of a specified character position counting from the right.

Note

Use the SUBSTRING function to extract a number of characters from the left. For more information, see SUBSTRING (SSIS).

Syntax

RIGHT(character_expression,integer_expression)

Arguments

  • character_expression
    Is a character expression from which to extract characters.
  • number
    Is an integer expression that indicates the number of characters returned.

Result Types

DT_WSTR

Remarks

If integer_expression is greater than the length of character_expression, the function returns character_expression.

If integer_expression is zero, the function returns a zero-length string.

If integer_expression is a negative number, the function returns an error.

The number argument can take variables and columns.

RIGHT works only with the DT_WSTR data type. A character_expression argument that is a string literal or a data column with the DT_STR data type is implicitly cast to the DT_WSTR data type before RIGHT performs its operation. Other data types must be explicitly cast to the DT_WSTR data type. For more information, see Integration Services Data Types and Cast (SSIS).

RIGHT returns a null result if either argument is null.

Examples

This example uses a string literal. The return result is "Bike".

RIGHT("Mountain Bike", 4)

This example returns the number of right-most characters that is specified in the Times variable, from the Name column. If Name is Touring Front Wheel and Times is 5, the return result is "Wheel".

RIGHT(Name, @Times)

This example also returns the number of right-most characters that is specified in the Times variable, from the Name column. Times has a noninteger data type and the expression includes an explicit cast to the DT_I2 data type. If Name is Touring Front Wheel and Times is 4.32, the return result is "heel". The value 4.32 is converted to 4 and the right four characters are returned.

RIGHT(Name, (DT_I2)@Times))

See Also

Other Resources

Functions (SSIS)

Help and Information

Getting SQL Server 2005 Assistance