.Net & SharePoint '07

Technical blog for .Net and all SharePoint 2007 related Information

About the author

Me(Prince) and my wife are B.E in I.T & C.S.E respectively.  I a certified MCPD: Web from 2007 Dec. I am Intrestes in Web Application, MOSS, EPM, etc.
Now working with Deira International School, as IT Application & Help Manager. I have started my career as "Software Developer" @  REACH Sewn Technologies and Consulting Pvt. Ltd, Bangalore India from Oct 2004 to Feb 2006, then as "Web & Intranet Developer" @ Fosroc International Ltd, Dubai from April 2006 to Sep 2009.
You can catch me on mail@jpy-tech.com or mail@princepy.com. Or on 00971 - 50 - 4284530 

Google Translate

Tag cloud

Calendar

<<  September 2010  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

View posts in large calendar

RecentComments

Comment RSS

Google Your Location


Parsing Alpha, Numeric, AlphaNumeric Characters in SQL 2005

CREATE FUNCTION dbo.ParseAlphaOnly
(
	@string VARCHAR(8000)
)
RETURNS VARCHAR(8000)
AS
BEGIN
	DECLARE @IncorrectCharLoc SMALLINT
	SET @IncorrectCharLoc = PATINDEX('%[^A-Za-z]%', @string)

	WHILE @IncorrectCharLoc > 0
	BEGIN
		SET @string = STUFF(@string, @IncorrectCharLoc, 1, '')
		SET @IncorrectCharLoc = PATINDEX('%[^A-Za-z]%', @string)
	END

	SET @string = @string
	RETURN @string
END
GO

CREATE FUNCTION dbo.ParseAlphaNumbersOnly
(
	@string VARCHAR(8000)
)
RETURNS VARCHAR(8000)
AS
BEGIN
	DECLARE @IncorrectCharLoc SMALLINT
	SET @IncorrectCharLoc = PATINDEX('%[^0-9A-Za-z]%', @string)

	WHILE @IncorrectCharLoc > 0
	BEGIN
		SET @string = STUFF(@string, @IncorrectCharLoc, 1, '')
		SET @IncorrectCharLoc = PATINDEX('%[^0-9A-Za-z]%', @string)
	END

	SET @string = @string
	RETURN @string
END
GO


CREATE FUNCTION dbo.ParseNumbersOnly
(
	@string VARCHAR(8000)
)
RETURNS VARCHAR(8000)
AS
BEGIN
	DECLARE @IncorrectCharLoc SMALLINT
	SET @IncorrectCharLoc = PATINDEX('%[^0-9]%', @string)

	WHILE @IncorrectCharLoc > 0
	BEGIN
		SET @string = STUFF(@string, @IncorrectCharLoc, 1, '')
		SET @IncorrectCharLoc = PATINDEX('%[^0-9]%', @string)
	END

	SET @string = @string
	RETURN @string
END
GO

--Test
SELECT dbo.ParseAlphaOnly('ABC”_I+{D[]}4|:e;””5,<.F>/?6')
GO
--Result
ABCIDeF

SELECT dbo.ParseAlphaNumbersOnly('ABC”_I+{D[]}4|:e;””5,<.F>/?6')
GO
--Result
ABCID4e5F6


SELECT dbo.ParseNumbersOnly('ABC”_I+{D[]}4|:e;””5,<.F>/?6')
GO
--Result
456

Categories: SQL 2005
Posted by Admin on Monday, December 28, 2009 10:47 PM
Permalink | Comments (0) | Post RSSRSS comment feed