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
 Pull everything up to the 3rd space in string

Author  Topic 

mwdallas
Starting Member

4 Posts

Posted - 2015-03-19 : 13:04:28
I am trying to figure out how to pull only a certain character string.

orig string varies in length (Varchar 50)
ex: MID - Proposed - Prime
ex: MID - NotProposed - NotPrime

I want to keep the first 6 characters 'MID - '
as well as up to the 3rd SPACE (not including the space)

so
ex: MID - Proposed
ex: MID - NotProposed

HELP please!

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2015-03-19 : 13:54:35
Here you go:

declare @s varchar(50)

set @s = 'MID - Proposed - Prime'

select LEFT(@s, charindex(' ', @s, 7) - 1)

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -