SQL SERVER – 2005 – UDF – User Defined Function to Strip HTML – Parse HTML – No Regular Expression

One of the developers at my company asked is it possible to parse HTML and retrieve only TEXT from it without using regular expression. He wanted to remove everything between < and > and keep only Text. I found the question very interesting and quickly wrote UDF which does not use regular expression. Let us see how to parse HTML without regular expression.

Read More

SQL SERVER – UDF – Function to Parse AlphaNumeric Characters from String

Following function keeps only Alphanumeric characters in string and removes all the other character from the string. This is very handy function when working with Alphanumeric String only. I have used this many times. CREATE FUNCTION dbo.UDF_ParseAlphaChars ( @string VARCHAR(8000) ) RETURNS VARCHAR(8000) AS BEGIN DECLARE @IncorrectCharLoc SMALLINT SET @IncorrectCharLoc…
Read More

SQL SERVER – User Defined Functions (UDF) to Reverse String – UDF_ReverseString

UDF_ReverseString UDF_ReverseString User Defined Functions returns the Reversed String starting from certain position. First parameters takes the string to be reversed. Second parameters takes the position from where the string starts reversing. Script of UDF_ReverseString function to return Reverse String. CREATE FUNCTION UDF_ReverseString ( @StringToReverse VARCHAR(8000), @StartPosition INT ) RETURNS…
Read More

SQL SERVER – UDF – User Defined Function to Extract Only Numbers From String

Following SQL User Defined Function will extract/parse numbers from the string. CREATE FUNCTION ExtractInteger(@String VARCHAR(2000)) RETURNS VARCHAR(1000) AS BEGIN DECLARE @Count INT DECLARE @IntNumbers VARCHAR(1000) SET @Count = 0 SET @IntNumbers = '' WHILE @Count <= LEN(@String) BEGIN IF SUBSTRING(@String,@Count,1) >= '0' AND SUBSTRING(@String,@Count,1) <= '9' BEGIN SET @IntNumbers =…
Read More