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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 i need to select everything in field between "-" &

Author  Topic 

cwfontan
Yak Posting Veteran

87 Posts

Posted - 2009-08-24 : 11:37:10
i need to select everything in field between "-" to end.
last two cars will always be state.. everything in between - and state will always be city.

I need to select city and state as seperate expressions

Strings = "This is myName - New Orleans LA"


Thanks

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2009-08-24 : 11:44:16
Well, here's one way:


declare @txt varchar(100)

set @txt = 'This is myName - New Orleans LA'

select substring(@txt,charindex('-',@txt)+1,(len(@txt)-(charindex('-',@txt)+1) -2))
Go to Top of Page
   

- Advertisement -