Posts

Showing posts with the label Transact-SQL

Logical functions - LEAST

Image
This function returns the minimum value from a list of one or more expressions. Syntax:   LEAST ( expression1 [ , ...expressionN ] ) Returns the data type with the highest precedence from the set of types passed to the function. Example 1: SELECT LEAST ( '6.62' , 3.1415 , N'7' )   AS  LeastVal ; GO Above query will returns least value as 3.145 Example 2: SELECT LEAST ( 'Glacier' , N'Joshua Tree' , 'Mount Rainier' ) AS  LeastString ; GO Above  example returns the minimum value from the list of character constants that is provided. Remarks All expressions in the list of arguments must be of a data type that is comparable and that can be implicitly converted to the data type of the argument with the highest precedence. Implicit conversion of all arguments to the highest precedence data type takes place before comparison. If implicit type conversion between the arguments isn't supported, the function will fail and return an error .

STRING_AGG (Transact-SQL)

Image
Concatenates the values of string expressions and places separator values between them. The separator isn't added at the end of string. Syntax:      STRING _ AGG ( expression, separator ) [ <order_clause> ] <order_clause> ::= WITHIN GROUP ( ORDER BY <order_by_expression_list> [ ASC | DESC ] ) Arguments expression Is an expression of any type. Expressions are converted to  NVARCHAR  or  VARCHAR  types during concatenation. Non-string types are converted to  NVARCHAR  type. separator Is an expression of  NVARCHAR  or  VARCHAR  type that is used as separator for concatenated strings. It can be literal or variable. <order_clause> Optionally specify order of concatenated results using  WITHIN GROUP  clause: WITHIN GROUP ( ORDER BY <order_by_expression_list> [ ASC | DESC ] ) <order_by_expression_list> A list of non-constant expression...