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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Triming SQL string

Author  Topic 

Radhiga
Starting Member

35 Posts

Posted - 2006-04-15 : 00:35:57
Hai friends,
I have the IP address stored in DB in the following format
IN:192.22.22.22:1968
from this string i need to find only the IP address...
Sometimes i maynot have the Port address ie, last four digit...
to find the first 3 charatcters i can use charindex('IN:',string)..
but to find the last four characters, i dont know how to do..
help pls

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-04-15 : 01:43:31
Somthing like this ..


Declare @Tmp Table
(
Ip_Add Varchar(20)
)

Insert @Tmp
Select '192.22.22.22:1968' Union All
Select '192.22.22.22' Union All
Select '192.22.22.22:808'
Union All
Select '192.22.22.2'

Select Replace(Ip_Add,SubString(Ip_Add,CharIndex(':',Ip_Add),Len(Ip_Add)),'') From @Tmp
Where CharIndex(':',Ip_Add)>0



If Debugging is the process of removing Bugs then i Guess programming should be process of Adding them.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-04-17 : 02:24:05
or

select left(Ip_Add, charindex(':',Ip_add,1)-1) from @tmp
Where CharIndex(':',Ip_Add)>0

Madhivanan

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

- Advertisement -