1 Previous Next 

SQLCLR: Create a custom function


Store a persons full name in the name field of one my sql express database which I wanted to sort by the last name. 

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Imports Microsoft.SqlServer.Server

Partial Public Class UserDefinedFunctions
    <Microsoft.SqlServer.Server.SqlFunction()> _
    Public Shared Function LastWord(ByVal word As SqlString) As SqlString
        ' Add your code here
        Dim strWords() As String = word.ToString.Split(" "c)
        Return New SqlString(strWords(strWords.GetUpperBound(0)))
    End Function
End Class




1 Previous Next