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 |
|
azmi
Starting Member
37 Posts |
Posted - 2006-04-18 : 05:10:26
|
| [code] Hi guys, do you have any idea how to retrieve packing_mode from description field.Is that possible cause description length is not consistant. Your idea is welcome...description packing_mode----------- ------------Fudgio 75x24:Special Goods 75x24Sesamio 150x12:Special Goods 150x12Cheesti 225x12:Special Goods 225x12Cream Crk 400gx12:Special Goods 400gx12Margie 400gx12:Special Goods 400gx12[/code] |
|
|
RyanRandall
Master Smack Fu Yak Hacker
1074 Posts |
Posted - 2006-04-18 : 06:03:38
|
Hi azmi,This works with your sample data. It uses the colon and the space prior to it, so if you have data which does not fit that, then this may not work...  --datadeclare @t table (description varchar(50))insert @t select 'Fudgio 75x24:Special Goods'union all select 'Sesamio 150x12:Special Goods'union all select 'Cheesti 225x12:Special Goods'union all select 'Cream Crk 400gx12:Special Goods'union all select 'Margie 400gx12:Special Goods'--calculationselect description, right(ChoppedToColon, charindex(' ', reverse(ChoppedToColon))-1) as packing_modefrom (select description, left(description, charindex(':', description)-1) as ChoppedToColon from @t) aRyan Randallwww.monsoonmalabar.com London-based IT consultancy Solutions are easy. Understanding the problem, now, that's the hard part. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-04-18 : 06:04:39
|
Cant you use Front end application to split the data and extract accordingly?Otherwise you can consider this approachSelect description, reverse(substring(reverse(substring(description,1,charindex(':',description,1)-1)),1, charindex(' ', reverse(substring(description,1,charindex(':',description,1)-1)))-1)) as Packing_codefrom( select 'Fudgio 75x24:Special Goods' as description union all select 'Sesamio 150x12:Special Goods' union all select 'Cheesti 225x12:Special Goods' union all select 'Cream Crk 400gx12:Special Goods' union all select 'Margie 400gx12:Special Goods' ) TAlso coery has excellant function to retreive whatever you wantRefer thishttp://www.sqlteam.com/forums/topic.asp?TOPIC_ID=56713MadhivananFailing to plan is Planning to fail |
 |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2006-04-18 : 06:13:39
|
| I'm sure it can be done easier, but:[code]create table #tbl (description varchar(100))insert into #tblselect 'Fudgio 75x24:Special Goods'union select 'Sesamio 150x12:Special Goods'union select 'Cheesti 225x12:Special Goods'union select 'Cream Crk 400gx12:Special Goods'union select 'Margie 400gx12:Special Goods'select ltrim(reverse(substring(reverse(substring(description,1,charindex(':',description))),2,charindex(' ',reverse(substring(description,1,charindex(':',description))))-1))) from #tbldrop table #tbl[code]EDIT: Got double sniped, too much work got in the way.. |
 |
|
|
|
|
|
|
|