I have the following SQL CLR C# UDF:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using System.Collections;
using System.Text;
public partial class UserDefinedFunctions
{
[Microsoft.SqlServer.Server.SqlFunction]
public static SqlString clrFn_GetDigits(string theWord)
{
if (theWord == null) { theWord = ""; }
string newWord = "";
char[] KeepArray = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '\\', '/', '-', ' '};
foreach (char thischar in theWord)
{
foreach (char keepchar in KeepArray)
{
if (keepchar == thischar)
{
newWord += thischar;
}
}
}
return (SqlString)(newWord.Trim());
}
}
This works great so far except for addresses like the below:
141A, Some Street Avenue
4b, St Georges Street
16E Test Avenue
I want my function to return 141A, 4b and 16E
Any ideas?
I have not tested the below code, but something along those lines, some error checking will need to be in place to ensure the converts do not fail but this solution gives you what you need