h1.post-title { color:orange; font-family:verdana,Arial; font-weight:bold; padding-bottom:5px; text-shadow:#64665b 0px 1px 1px; font-size:32px; } -->

Pages

Extract Character from string in SQL

          Today, we see the Extract character from String in SQL Server
Alter FUNCTION ExtractCharacter(@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) <> '1' AND SUBSTRING(@String,@Count,1) <> '2' AND SUBSTRING(@String,@Count,1) <> '3' AND SUBSTRING(@String,@Count,1) <> '4'AND SUBSTRING(@String,@Count,1) <> '5' AND SUBSTRING(@String,@Count,1) <> '6' AND SUBSTRING(@String,@Count,1) <> '7' AND SUBSTRING(@String,@Count,1) <> '8' AND SUBSTRING(@String,@Count,1) <> '9' BEGIN SET @IntNumbers = @IntNumbers + SUBSTRING(@String,@Count,1) END SET @Count = @Count + 1 END RETURN @IntNumbers END GO