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

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

cipriani1984
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
Hi,

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'?

Thanks

rohitvishwakarma
Posting Yak Master

India
232 Posts

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

DECLARE @data VARCHAR(200)
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

visakh16
Very Important crosS Applying yaK Herder

India
52309 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
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.08 seconds. Powered By: Snitz Forums 2000