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
 Transact-SQL (2000)
 simple string question

Author  Topic 

mike13
Posting Yak Master

219 Posts

Posted - 2006-06-21 : 07:45:13
Hi all,

I got an ip 128.13.132.1
How do i cut this string in SQL to look like this
128.13.132. ?

Thanks a lot,

Roland

mwjdavidson
Aged Yak Warrior

735 Posts

Posted - 2006-06-21 : 08:21:23
Try:

DECLARE @str VARCHAR(20)
SET @str = '128.13.132.1'

SELECT LEFT(@str, LEN(@str) - CHARINDEX('.', REVERSE(@str))+1)


Mark
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-06-21 : 08:46:16
If there are always four parts, then

Select parsename(@str,4)+'.'+parsename(@str,3)+'.'+parsename(@str,2)

Madhivanan

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

mike13
Posting Yak Master

219 Posts

Posted - 2006-06-21 : 09:05:03
Thanks a lot guys that did the job!!
Go to Top of Page
   

- Advertisement -