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 |
|
IBoonZ
Yak Posting Veteran
53 Posts |
Posted - 2009-04-09 : 06:38:32
|
| hii got following dataABC_COSABC_COSDEF-00DEF-00ZER-00JFK_COSi want in a case fucntion following when i got 2 decimals, like DEF-00i want DE00, so the F gone and '-'(i tried with stuff(substring) but then i only can or remove the '-' or the 'F', i need both to be gone.and when i got JFK_COS or ABC_COS i want that to stay.so i need to filter on that or something :/.Ty |
|
|
theboyholty
Posting Yak Master
226 Posts |
Posted - 2009-04-09 : 06:42:00
|
| You could use the REPLACE function.e.g.REPLACE(field_name,'F-','')which looks for the characters 'F-' and strips them out. |
 |
|
|
karthik_padbanaban
Constraint Violating Yak Guru
263 Posts |
Posted - 2009-04-09 : 07:21:50
|
| try this one select case isnumeric(right(column1,2)) when 1 then left(column1,charindex('-',column1)-2)+right(column1,2) else column1 end as column1 from tbaleKarthik |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-04-09 : 07:32:20
|
| select data,case when data like '%_00' then stuff(data,3,2,'') else data end from(select 'ABC_COS' as data union allselect 'ABC_COS' union allselect 'DEF-00' union allselect 'DEF-00' union allselect 'ZER-00' union allselect 'JFK_COS' ) as tMadhivananFailing to plan is Planning to fail |
 |
|
|
thiyagu_rind
Starting Member
46 Posts |
Posted - 2009-04-09 : 07:37:33
|
| Hi, You can use the CASE directly with the query, something like thisselect case name when 'DEF-00' THEN 'DE00' else name end as Namefrom tableRegardsThiyagarajan |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-04-09 : 08:23:38
|
quote: Originally posted by thiyagu_rind Hi, You can use the CASE directly with the query, something like thisselect case name when 'DEF-00' THEN 'DE00' else name end as Namefrom tableRegardsThiyagarajan
Thats not generalised MadhivananFailing to plan is Planning to fail |
 |
|
|
Kokkula
Starting Member
41 Posts |
Posted - 2009-04-13 : 05:46:41
|
| Hello,Adding more generalized by not mentioning the locations, instead of it getting the exact locations from the stringselect data,case when data like '%_00' then stuff(data,CHARINDEX('-',Data,1)-1,2,'') else data end from(select 'ABC_COS' as data union allselect 'ABC_COS' union allselect 'DEF-00' union allselect 'DEF-00' union allselect 'ZERF-00' union allselect 'ZER-00' union allselect 'JFK_COS' ) as tHope helpful...Thanks,Pavan |
 |
|
|
|
|
|
|
|