| Author |
Topic |
|
WoodHouse
Posting Yak Master
211 Posts |
Posted - 2009-11-12 : 05:11:12
|
HiI have data like this...create table #test( Accounts VARCHAR(500)) --Test Valuesinsert into #test values('SDS3232')insert into #test values('SS3FG262')insert into #test values('SDS3TR28G2')insert into #test values('SDSE3R2G32')insert into #test values('SDS3212RR')insert into #test values('SDS3235FGT')insert into #test values('1234')I need remove all the characters and returns only numeric.I have done like this...CREATE FUNCTION dbo.cahr(@Input varchar(1000))RETURNS VARCHAR(1000)BEGIN DECLARE @Pos INT SET @Pos = PATINDEX('%[^0-9]%',@Input) WHILE @Pos > 0 BEGIN SET @Input = STUFF(@Input,@Pos,1,'') SET @Pos = PATINDEX('%[^0-9]%',@Input) END RETURN @InputENDGOGuys any other smart method...pls....thanks |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-11-12 : 05:16:29
|
fnFilterString KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
WoodHouse
Posting Yak Master
211 Posts |
Posted - 2009-11-12 : 05:31:05
|
| Hi KHI need only string The link i think its only for Digits... |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-11-12 : 05:38:37
|
[code]SELECT dbo.fn_FilterString('SDS3TR28G2', '[^0-9]', 0)orselect dbo.fnFilterString('SDS3TR28G2', '[^0-9]')[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
WoodHouse
Posting Yak Master
211 Posts |
Posted - 2009-11-12 : 06:08:05
|
| Hi madhiyour blog is restricted here please post ur query here if possible.thanks |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-11-12 : 07:16:18
|
quote: Originally posted by WoodHouse Hi madhiyour blog is restricted here please post ur query here if possible.thanks
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 MadhivananFailing to plan is Planning to fail |
 |
|
|
WoodHouse
Posting Yak Master
211 Posts |
Posted - 2009-11-12 : 07:22:34
|
| HiThanks a lot madhi....I need only chars so i have done bit alter... |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-11-12 : 07:36:00
|
| Change [0-9] to [a-z]MadhivananFailing to plan is Planning to fail |
 |
|
|
WoodHouse
Posting Yak Master
211 Posts |
Posted - 2009-11-12 : 07:41:14
|
| Hi yes i did same... |
 |
|
|
|