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
 Get rid of everyhting after .

Author  Topic 

Topaz
Posting Yak Master

199 Posts

Posted - 2008-01-03 : 05:56:41
I have some data in a field called website3 which looks like this:

Skidrive.Co.Uk
Principles.Co.Uk

And basically it should look like this

Skidrive
Principles

Is there any SQL command that i can write which will get rid of everything after and including the '.' if a dot appears in the website3 field.

Thanks

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-01-03 : 06:03:46
[code]declare @a varchar(20)

set @a = 'Skidrive.Co.Uk'

select left(@a, charindex('.', @a)-1) as stripped_name[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

Topaz
Posting Yak Master

199 Posts

Posted - 2008-01-03 : 06:14:52
Hmmm...

I cant really see whats going on here, but i probably forgot to mention that there are 40,000 records that need to be updated this way.

And from that it looks to me like i will have to enter each matching record?
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-01-03 : 07:33:32
quote:
Originally posted by Topaz

Hmmm...

I cant really see whats going on here, but i probably forgot to mention that there are 40,000 records that need to be updated this way.

And from that it looks to me like i will have to enter each matching record?



Run this and see

Select left(yourcolumn,charindex('.',yourcolumn)-1) from yourtable

Madhivanan

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

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2008-01-03 : 15:46:16
Maybe this?
DECLARE @Yak TABLE(website3 VARCHAR(255))

INSERT @Yak
SELECT 'Skidrive.Co.Uk'
UNION ALL SELECT 'Principles.Co.Uk'
UNION ALL SELECT 'Foo.com'


SELECT PARSENAME(website3, 3)
FROM @Yak

-- OR
SELECT COALESCE(PARSENAME(website3, 3), PARSENAME(website3, 2))
FROM @Yak
Go to Top of Page
   

- Advertisement -