T-SQL String Functions

  • Share
  • Print this article

Transact-SQL or T-SQL is Microsoft's version of the SQL database language. Computer communications with Microsoft's proprietary SQL Server must be written in T-SQL. String functions in T-SQL manipulate character strings, sections of text stored as a list of characters or numbers. The syntax for using functions takes the form of "select function_name (argument)."

  1. Arguments

    • Arguments are the variables, formed of numbers or strings, that functions work upon. In T-SQL, a function working on the argument "char_expr," for example, affects strings of text characters. Function_name (integer_expr) means the function deals with integers of various kinds. When you need to perform a database operation, look for a function that can manipulate the argument -- character strings, numbers or variables -- that you want to use. Then identify the specific string or kind of string you're interested in.

    Functions

    • Different functions work on different arguments in T-SQL. Ascii, for example, works on the char_expr argument: It returns a result in ASCII code identifying the first character in the string. Char_length works on the same argument and gives you the total number of characters in a variable string. "Lower" converts upper-case characters to lower case and "reverse" turns strings around -- "jklm" becomes "mlkj" if the reverse function affects that character string.

    Determinism

    • T-SQL string functions are deterministic. If the database hasn't changed its contents, a function will always give the same result when applied to the same set of input values. Nondeterministic functions come up with a different result every time, even if the database state remains the same. None of SQL Server's built-in string functions, such as ascii, can be changed to become nondeterministic. Determinism makes it simpler for the server to index the results of a T-SQL function.

    Considerations

    • The presence of character strings and functions may not be obvious to database users. T-SQL works with applications that include an interface for selecting the data with which users want to work or that call up data by use of general language rather than writing function_name (argument). If you want to identify the price of a particular product, for example, T-SQL could use a function to gather the data from the server in the form of "the price is" paired with the amount.

Related Searches

References

Resources

Comments

Related Ads

Featured
View Mobile Site