Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Name matching
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Constraint Violating Yak Guru

United Kingdom
304 Posts

Posted - 09/30/2010 :  06:15:50  Show Profile  Click to see cipriani1984's MSN Messenger address  Reply with Quote

I have the following field from a data source which is abit annoying I would like to strip it out.

Field1 = 'sname / fname title'

LEFT(Field1, ISNULL(NULLIF (CHARINDEX('/', Field1) - 1, - 1), LEN(Field1)))

This returns the 'sname' for me, how would i strip out the 'fname' only and ignore the 'title'?


Posting Yak Master

232 Posts

Posted - 09/30/2010 :  06:53:09  Show Profile  Reply with Quote

SET @data = 'sname / fname title'

DECLARE @data_2 VARCHAR(100)
SET @data_2 = SUBSTRING(@data,CHARINDEX('/',@data)+1 ,LEN(@data))
SELECT  RIGHT(LTRIM(@data_2),CHARINDEX(' ', LTRIM(@data_2)))
Go to Top of Page

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 09/30/2010 :  12:59:31  Show Profile  Reply with Quote
STUFF(Field1,1,ISNULL(NULLIF (CHARINDEX('/', Field1) + 1, 1), 0),'')

SQL Server MVP

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000