docs.intersystems.com
Home / InterSystems SQL Reference / SQL Functions / LEFT

InterSystems SQL Reference
LEFT
Previous section           Next section
InterSystems: The power behind what matters   
Search:  


A scalar string function that returns a specified number of characters from the beginning (leftmost position) of a string expression.
Synopsis
{fn LEFT(string-expression,count)}
Arguments
string-expression A string expression, which can be the name of a column, a string literal, or the result of another scalar function, where the underlying data type can be represented as any character type (such as CHAR or VARCHAR).
count An integer that specifies the number of characters to return from the starting position of string-expression.
Description
LEFT returns the specified number of characters from the beginning of a string. LEFT does not pad strings; if you specify a larger number of characters than are in the string, LEFT returns the string. LEFT returns NULL if passed a NULL value for either argument.
LEFT can only be used as an ODBC scalar function (with the curly brace syntax).
Examples
The following example returns the seven leftmost characters from each name in the Sample.Person table:
SELECT Name,{fn LEFT(Name,7)}AS ShortName
     FROM Sample.Person
The following embedded SQL example shows how LEFT handles a count that is longer than the string itself:
   &sql(SELECT Name,{fn LEFT(Name,40)}
   INTO :a,:b
   FROM Sample.Person)
   IF SQLCODE'=0 {
     WRITE !,"Error code ",SQLCODE }
   ELSE {
     WRITE !,a,"=original",!,b,"=LEFT 40" }
No padding is performed.
See Also
LTRIM RIGHT RTRIM


Previous section           Next section
View this book as PDF   |  Download all PDFs
Copyright © 1997-2019 InterSystems Corporation, Cambridge, MA
Content Date/Time: 2019-04-10 14:45:57