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.
| Author |
Topic |
|
cplusplus
Aged Yak Warrior
567 Posts |
Posted - 2011-09-28 : 10:01:31
|
| declare @Sample table (Proj_name varchar(100))insert @Sampleselect 'SPIA 1 -AJ - ASESORIA JURIDICA' union allselect 'EQN 1 - DS- DERECHO SUPERFICIARIOS' union allselect 'PTB 1 - DS - DERECHO SUPERFICIARIOS' union allselect 'ENS 1 - AJ - ASESORIA JURIDICA' union allselect 'VET 1 - GS - DERECHOS SUPERFICIARIOS' union allselect 'VET 2 - GS - DERECHOS SUPERFICIARIOS' union allselect 'VET 3 - DS - DERECHOS SUPERFICIARIOS' union allselect 'VET 4 - DS - DERECHOS SUPERFICIARIOS' union allselect 'COC 1 - DS - DERECHOS SUPERFICIARIOS' union allselect 'COC 2 - AJ - ASESORIA JURIDICA' union allselect 'PEL 1 - DS - DERECHOS SUPERFICIARIOS' union all'i want to pick project name that are in the above formats only, with two hyphens, and get just the middlepart between hyphens removing any null spaces, is it possible.my resultset should be:AJDSGS |
|
|
Lewie
Starting Member
42 Posts |
Posted - 2011-09-28 : 10:40:59
|
| select replace(left(substring(Proj_name,CHARINDEX('-',Proj_name,1) + 1,LEN(Proj_name) - CHARINDEX('-',Proj_name,1) ) ,CHARINDEX('-',substring(Proj_name,CHARINDEX('-',Proj_name,1) + 1,LEN(Proj_name) - CHARINDEX('-',Proj_name,1))) - 1),' ','')from @Sample |
 |
|
|
cplusplus
Aged Yak Warrior
567 Posts |
Posted - 2011-09-28 : 10:49:25
|
| Lewie,It worked, Thank you very much. |
 |
|
|
|
|
|
|
|