Geeks Talk

Prepare for your Next Interview




SQL Server Replace Function

This is a discussion on SQL Server Replace Function within the SQL Server forums, part of the Databases category; Hello, i am looking for sql server equivalent function for this ... Could some one help me ... PHP Code: function  removealphas  ( byval alphanum  as  variant )  ...


Go Back   Geeks Talk > Databases > SQL Server

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 01-30-2007
Expert Member
 
Join Date: Sep 2005
Posts: 110
Thanks: 8
Thanked 26 Times in 15 Posts
suji is on a distinguished road
SQL Server Replace Function

Hello, i am looking for sql server equivalent function for this ...

Could some one help me ...

PHP Code:
function removealphas (byval alphanum as variant
dim clean as string dim posa_charpos 

if isnull(alphanumthen 
exit function f
or pos 1 to len(alphanum
a_char$ = mid(alphanumpos1
if 
a_char$ >= "0" and a_char$ <= "9" 
then clean$ = clean$ + a_char
end if 
next 
pos removealphas 
clean
end function 
thanks, suji
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-30-2007
Expert Member
 
Join Date: Jun 2006
Posts: 140
Thanks: 2
Thanked 12 Times in 9 Posts
Jim.Anderson is on a distinguished road
Re: SQL Server Replace Function

CREATE FUNCTION dbo.REMOVEALPHA
(@str VARCHAR(8000))
RETURNS VARCHAR(8000)

BEGIN
declare @validchars varchar(8000)
set @validchars = '0-9'
WHILE PATINDEX('%[^' + @validchars + ']%',@str) > 0
SET @str=REPLACE(@str, SUBSTRING(@str ,PATINDEX('%[^'
+ @validchars +']%',@str), 1) ,'')
RETURN @str
END
GO



Execuete:
SELECT dbo.REMOVEALPHA('REPLACEAPHA1111122')
Reply With Quote
Reply

  Geeks Talk > Databases > SQL Server


Thread Tools
Display Modes


Similar Threads

Thread Thread Starter Forum Replies Last Post
replace the symbols... psuresh1982 Brainteasers 1 01-30-2007 01:57 AM
DNS server in Windows server 2000 FantaGuy Web Servers 2 12-13-2006 03:21 PM
replace the letters.......... psuresh1982 Brainteasers 2 11-29-2006 01:50 AM
Microsoft CRM : Install Microsoft Dynamics CRM 3.0 Server using a Microsoft Exchange Server cluster environment Jim.Anderson Microsoft CRM 0 09-27-2006 07:39 AM
Microsoft CRM : Installing Microsoft CRM 3.0 Server using a Microsoft SQL Server cluster environment Jim.Anderson Microsoft CRM 0 09-27-2006 07:39 AM


All times are GMT -4. The time now is 03:12 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Copyright © 2008 GeekInterview.com. All Rights Reserved