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
 Other Forums
 Other Topics
 truncate part of a sql result

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2007-02-21 : 07:44:08
Mike writes "I have a dbase with an about us field (is full url) and contactinfo field (part of a url) and want to combine the result but remove only the second part of the about us field (i.e. the 'profile.html' in the middle part of the combined result shown below):


SELECT _aboutus_url +_contactinfo_html
FROM database.dbo._LINKS

Result:

http://abc.com/profile.html/contactinfo.html
http://xyz.com/profile.html/contactinfo.html


Any help is much appreciated!"

mwjdavidson
Aged Yak Warrior

735 Posts

Posted - 2007-02-21 : 08:24:03
[code]DECLARE @about_us VARCHAR(255)
DECLARE @contact VARCHAR(255)
SET @about_us = 'www.abc.com/profile.html'
SET @contact = 'contactinfo.html'
SELECT LEFT(@about_us, PATINDEX('%/%.html%', @about_us)) + @contact
[/code]
This relies up _aboutus_url ending in '.html'.

Mark
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-02-21 : 08:47:54
Something similar to this

SELECT LEFT(AboutUs, LEN(AboutUs) - 12) + ContactInfo
FROM Database.dbo.Links


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -