Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Below is the answer to resolve:


<pre lang="SQL">
Declare @str varchar(100)
Declare @ln INT
Declare @cnt INT
Declare @sts INT
Declare @stsinsrt INT
set @stsinsrt=1
set @cnt=0
Declare @curchr varchar(100)
Declare @finalstr varchar(100)
set @str='dsfdsf43543543sfas34534asf4354 Rajnish375747893897389538475'

set @ln=(select LEN(@str))
DECLARE @tmp TABLE 
(
res varchar(100)
)
while (@cnt<@ln)
begin
set @curchr =(select SUBSTRING(@str,@cnt,1))
set @sts=(SELECT ISNUMERIC(@curchr))

if(@sts=0)
begin
if(@stsinsrt=1)
begin
set @stsinsrt=0
insert into @tmp values(@curchr)
end
else
update @tmp set res=res+@curchr
end
set @cnt=@cnt+1

end

SELECT *
FROM @tmp
Posted
Comments
Abhinav S 5-Sep-12 10:20am    
This is the question answer forum. What is your question?
[no name] 5-Sep-12 10:21am    
"Below is the answer to resolve", so you expect us to come with a question?
Sandeep Mewara 5-Sep-12 11:03am    
This is not a well framed question! We cannot work out what you are trying to do/ask from the post. Please elaborate and be specific.
Use the "Improve question" link to edit your question and provide better information.

1 solution

Hi..
See the below code...
it will return you all isnumeric value in single variable and not isnumeric value in another variable..

SQL
declare @str varchar(100)
declare @cnt int
declare @letter int
declare @nstr varchar(100) 
declare @vstr varchar(100) 
set @vstr=''
set @nstr=''
set @str ='dsfdsf43543543sfas34534asf4354 Rajnish375747893897389538475'
set @cnt = 1
while @cnt < len(@str)
begin
 select @letter = isnumeric(substring(@str,@cnt,1))
	if @letter = 1
	  begin 
	    set @nstr=@nstr+substring(@str,@cnt,1) 
	  end 
	else
	  begin 
	    set @vstr=@vstr+substring(@str,@cnt,1) 
	  end
  set @cnt=@cnt+ 1
end
print @nstr  -- return isnumeric value
print @vstr  -- returns not isnumeric value
 
Share this answer
 
v2
Comments
Santhosh Kumar Jayaraman 6-Sep-12 8:21am    
+5
ssd_coolguy 6-Sep-12 8:25am    
Thanks Santosh..:-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900