Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Not sure what to subsitute and where...?

Author  Topic 

jarredcody
Starting Member

5 Posts

Posted - 2010-03-24 : 21:56:22
Will this work if the field name is PHONE_NUMBER in the table PHONE, database RWD?

Not sure what to subsitute and where...?


**************************************************************

UPDATE [RWD].[dbo].[PHONE]

Declare @s varchar(100),@result varchar(100)set @s='as4khd0939sdf78'

set @result=''
select
@result=@result+case when number like '[0-9]' then number else '' end from
(
select substring(@s,number,1) as number from
(
select number from master..spt_values where type='p' and number between 1 and len(@s)
) as t
) as t
select @result as only_numbers
select case when left(@result,1)='1' then stuff(@result,1,1,'') else @result end as number

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-03-25 : 02:07:47
what are you trying to do ?

Vaibhav T
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-03-25 : 02:49:53
You can use this
http://beyondrelational.com/blogs/madhivanan/archive/2009/08/03/regular-expression.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-25 : 11:42:42
quote:
Originally posted by jarredcody

Will this work if the field name is PHONE_NUMBER in the table PHONE, database RWD?

Not sure what to subsitute and where...?


**************************************************************

UPDATE [RWD].[dbo].[PHONE]

Declare @s varchar(100),@result varchar(100)set @s='as4khd0939sdf78'

set @result=''
select
@result=@result+case when number like '[0-9]' then number else '' end from
(
select substring(@s,number,1) as number from
(
select number from master..spt_values where type='p' and number between 1 and len(@s)
) as t
) as t
select @result as only_numbers
select case when left(@result,1)='1' then stuff(@result,1,1,'') else @result end as number


you need make code snippet into a function and then use it in update


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -