The StringManipulate sample for Microsoft SQL Server 2005 demonstrates supplementary character aware string processing. This sample shows the implementation of five Transact-SQL string functions that provide the same string manipulation functions as built-in ones, but with additional supplementary character-aware capability to handle both Unicode and supplementary character strings. The five functions are len_s(), left_s(), right_s(), sub_s() and replace_s() which equivalent to built-in’s LEN(), LEFT(), RIGHT(), SUBSTRING() and REPLACE() string functions.

Note:
When compiling CLR Integration samples, the path of the version of the Microsoft .NET Framework compiler that was included with SQL Server 2005 must be the first Framework directory in the PATH environment variable. The location of the compiler that was included with SQL Server 2005 is either drive:\WINNT\Microsoft.NET\Framework\v2.0.xxxxx or drive:\Windows\Microsoft.NET\Framework\v2.0.xxxxx, where drive is the installation drive and xxxxx is the version of the .NET Framework that was included with SQL Server.

Default Location: drive:\Program Files\Microsoft SQL Server\90\Samples\Engine\Programmability\CLR\StringManipulate

Scenario

A developer wants to accurately manipulate Unicode strings that contain supplementary characters.

Languages

Transact-SQL, Visual C# and Visual Basic.

Features

The StringManipulate sample uses the following features of .

Application Area Features

Overall

CLR user-defined function

Prerequisites

Before running this sample, make sure the following software is installed:

  • Microsoft SQL Server 2005 or Microsoft SQL Server 2005 Express Edition (SQL Server Express). You can obtain SQL Server Express free of charge from the SQL Server 2005 Express Edition Documentation and Samples Web site

  • The AdventureWorks database, which is included with SQL Server 2005, and is also available at the SQL Server 2005 Express Edition Documentation and Samples Web site.

  • The SQL Server 2005 Database Engine samples. These samples are included with SQL Server 2005, and are also included within the Microsoft Microsoft .NET Framework version 2.0 SDK 2.0.

  • .NET Framework SDK 2.0 or Microsoft Visual Studio 2005. You can obtain .NET Framework SDK free of charge. See Installing the .NET Framework SDK.

  • Ext-B font must be installed on the computer for the correct characters to appear in the SQL Server Management Studio results window. To change the font in the results window in SQL Server Management Studio, on the Tools menu, click Options, expand Environment, and then click Fonts and Colors. Set the font to MingLiU_ExtB for Text Results and/or Grid Results. You must close and then reopen SQL Server Management Studio for the changes to take effect.

Building the Sample

To build the sample, do the following:

Build the sample

  1. CD to the install directory and execute the following at a .NET Framework or Microsoft Visual Studio 2005 command prompt:

    sn -k keypair.snk

  2. Compile the sample by using Visual Studio 2005 and the provided Visual Studio solution, or by using Microsoft MSBuild, which is included in the .NET Framework SDK 2.0, by executing a command similar to the following at the command prompt:

    msbuild /nologo /verbosity:quiet /property:Configuration=Debug CS\ StringManipulate.sln

  3. Make sure that the AdventureWorks database is installed, or, if necessary, create the database in which you want to install the samples.

  4. If you did not install the SQL Server engine samples in the default location, modify the path in the CREATE ASSEMBLY part of the script in Scripts\InstallCS.sql and Scripts\InstallVB.sql to refer to location where the samples were installed.

  5. Open the scripts\installCS.sql or scripts\installVB.sql file, depending on whether you compiled the Visual C# project or the Visual Basic project, in . Execute the script that is contained in the file, or execute a command similar to the following at the command prompt:

    sqlcmd -E -I -i Scripts\InstallCS.sql

    This file contains script to install and register the sample common language runtime (CLR) objects into SQL Server.

Running the Sample

To run the sample, do the following:

Run the sample

  1. Open the scripts\test.sql file in SQL Server Management Studio. Execute the script that is contained in the file, or execute the following at the command prompt:

    sqlcmd -E -I -i Scripts\test.sql

    This script invokes the string manipulation sample from Transact-SQL.

Removing the Sample

To remove the StringManipulate sample, do the following:

Remove the sample

  1. Open the scripts\cleanup.sql file in SQL Server Management Studio. Execute the script that is contained in the file, or execute the following at the command prompt:

    sqlcmd -E -I -i Scripts\cleanup.sql

    This script removes the sample.

Comments

The CLR for SQL Server 2005 or SQL Server Express must be enabled for this sample to work correctly.

Samples are provided for educational purposes only. They are not intended to be used in a production environment and have not been tested in a production environment. Microsoft does not provide technical support for these samples. Sample applications and assemblies should not be connected to or used with your production SQL Server database or your report server without the permission of the system administrator.