.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> SQL Query >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Extract Character from string in SQL

Posted By:Narayanan       Posted Date: May 09, 2013    Points: 40    Category: SQL Query    URL: http://www.dotnetspark.com  

Today we will see the Extract Character from String in SQL
 

Here is SQL Query:

Create 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


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend