C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » SQL Server »

Query Plz!!


Posted Date: 06 Nov 2009      Posted By: Vasundhara      Member Level: Gold     Points: 1   Responses: 3



Hi All,

I have a small requirement.

I have am alphanumeric data in my database in one of my columns

For example

Data1

73200 MBR
CSV
65478 MDR

While retreving this particular data from database using select query i want to retrieve only alphabets in the particular column

Output:.

Data1

MBR
CSV
MDR

It should be like this..

Can anyone please help me on this...

Thanks in advance.






Responses

Author: dom    06 Nov 2009Member Level: SilverRating: 2 out of 52 out of 5     Points: 2

SQL is great with String operations. Many times, I use T-SQL to do my string operation. Let us see User Defined Function, which I wrote few days ago, which will return only Numeric values from AlphaNumeric values.

CREATE FUNCTION dbo.udf_GetNumeric
(@strAlphaNumeric VARCHAR(256))
RETURNS VARCHAR(256)
AS
BEGIN
DECLARE @intAlpha INT
SET @intAlpha = PATINDEX('%[^0-9]%', @strAlphaNumeric)
BEGIN
WHILE @intAlpha > 0
BEGIN
SET @strAlphaNumeric = STUFF(@strAlphaNumeric, @intAlpha, 1, '' )
SET @intAlpha = PATINDEX('%[^0-9]%', @strAlphaNumeric )
END
END
RETURN ISNULL(@strAlphaNumeric,0)
END
GO

/* Run the UDF with different test values */
SELECT dbo.udf_GetNumeric('') AS 'EmptyString';
SELECT dbo.udf_GetNumeric('asdf1234a1s2d3f4@@@') AS 'asdf1234a1s2d3f4@@@';
SELECT dbo.udf_GetNumeric('123456') AS '123456';
SELECT dbo.udf_GetNumeric('asdf') AS 'asdf';
SELECT dbo.udf_GetNumeric(NULL) AS 'NULL';
GO




this would help u...
Regards
Jaiho



Author: Mohan    06 Nov 2009Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

Check this link

http://www.dotnetspider.com/resources/29013-SQL-User-defined-Function-remove-numbers-from.aspx

Regards

Mohan Kumar.D



Author: Shameer    08 Nov 2009Member Level: SilverRating: 2 out of 52 out of 5     Points: 2

Select * from Production.Product Where Name like ‘%[A-Z]%’


Post Reply
You must Sign In to post a response.
Next : SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM ... . Ent
Previous : How to enter values into sqlce data table
Return to Discussion Forum
Post New Message
Category: SQL Server

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use