Functions on String Values - upper-case

THIS TOPIC APPLIES TO: yesSQL Server (starting with 2012)noAzure SQL DatabasenoAzure SQL Data Warehouse noParallel Data Warehouse

This function converts each character in $arg to its upper case equivalent. The Microsoft Windows binary case conversion for Unicode code points specifies how characters are converted to upper case. This standard is different than the mapping for Unicode standard code point standard.


fn:upper-case($arg as xs:string?) as xs:string  


Term Definition
$arg The string value to be converted to upper case.


If the value of $arg is empty, a zero length string is returned.


A. Changing a string to upper case

The following example changes the input string 'abcDEF!@4' to upper case.

DECLARE @x xml = N'abcDEF!@4';  
SELECT @x.value('fn:upper-case(/text()[1])', 'nvarchar(10)');  

B. Search for a Specific Character String

This example shows how to use the upper-case function to perform a case-insensitive search.

USE AdventureWorks  
--WITH XMLNAMESPACES clause specifies the namespace prefix  
--to use.   
--The XQuery contains() function is used to determine whether  
--any of the text nodes below the <Summary> element contain  
--the word 'frame'. The upper-case() function is used to make  
--the search case-insensitive.  

SELECT ProductModelID, CatalogDescription.query('  
         { /pd:ProductDescription/@ProductModelID }  
         { /pd:ProductDescription/pd:Summary }  
 ') as Result  
FROM Production.ProductModel  
where CatalogDescription.exist('  
          contains(upper-case(.), "FRAME")]')  = 1  

Here is the result set.

ProductModelID Result

-------------- ---------

19 <Prod ProductModelID="19">

<pd:Summary xmlns:pd="">

<p1:p xmlns:p1="">Our top-of-the-line competition mountain bike.

Performance-enhancing options include the innovative HL Frame,

super-smooth front suspension, and traction for all terrain.




25 <Prod ProductModelID="25">

<pd:Summary xmlns:pd="">

<p1:p xmlns:p1="">This bike is ridden by race winners. Developed with the

Adventure Works Cycles professional race team, it has a extremely light

heat-treated aluminum frame, and steering that allows precision control.




See Also

XQuery Functions against the xml Data Type