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 |
|
cdraves
Starting Member
2 Posts |
Posted - 2009-04-13 : 10:24:01
|
| This may be an esay question but I need a little help.I have a field that has the following information:Benefit \ Benefit Cards Request \ DentalI want to break this information into three fields:Field 1: BenefitField 2: Benefit Cards RequestField 3: DentalI know I can use:charindex(' \ ',DNACare_keys.KeyOptionName) to get the first part. But how would you get the information in the middle and on the end?I see that I may need to use a function. But is there any other way?Thanks, Carl |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-04-13 : 10:31:00
|
| declare @s varchar(100)set @s='Benefit \ Benefit Cards Request \ Dental'set @s=replace(@s,'\','.')select parsename(@s,3),parsename(@s,2),parsename(@s,1)MadhivananFailing to plan is Planning to fail |
 |
|
|
cdraves
Starting Member
2 Posts |
Posted - 2009-04-13 : 11:08:35
|
| This worked great. Thank you.Carl |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-04-14 : 07:28:52
|
| try this one toodeclare @s varchar(100)set @s='Benefit \ Benefit Cards Request \ Dental'select substring(@s,1,charindex('\',@s,1)-1),substring(@s,charindex('\',@s,1)+1,(charindex('\',@s,charindex('\',@s,1)+1)-charindex('\',@s,1))-1),right(@s,charindex('\',reverse(@s),1)-1) |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-04-15 : 02:56:23
|
quote: Originally posted by cdraves This worked great. Thank you.Carl
You are welcome MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|