CREATE ASSEMBLY SQLArrayBuilder FROM 'C:\SQLArrayBuilder.DLL'
WITH PERMISSION_SET = SAFE
GO
CREATE FUNCTION dbo.CountSalesOrderHeader
(@ArrayString nvarchar(400),
@ArrayDelimiter nchar(1),
@ArrayItemSelection smallint)
RETURNS nvarchar(400)
AS
EXTERNAL NAME SQLArrayBuilder.SQLArrayBuilder.ChooseValueFromArray
GO
SELECT dbo.CountSalesOrderHeader
('B,S', ',', 3) Choice
SELECT dbo.CountSalesOrderHeader
('B D', ',', 2) Choice
///////////////////
Imports System.Data
Imports System.Data.Sql
Imports System.Data.SqlTypes
Imports Microsoft.SqlServer.Server
Imports System.Text.RegularExpressions
Public Class SQLArrayBuilder
Public Shared Function ChooseValueFromArray(ArrayString as String, ArrayDelimiter as String, ArrayItemSelection as SqlInt16) as SqlString
Dim NewArrayString as String() = Regex.Split(ArrayString, ArrayDelimiter)
Dim NewArrayItemSelection as SqlInt16=ArrayItemSelection-1
Dim ReturnString as SQLString = NewArrayString(NewArrayItemSelection)
Return ReturnString
End Function
End Class