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 |
|
satheesh
Posting Yak Master
152 Posts |
Posted - 2011-09-30 : 08:49:36
|
| Dear All I have policyid field and I try to select all policyid which has ‘JUU’ as prefix.Select policyid from policy where policyid like ‘%JUU%’ResultJUU1534322JUU1596832IPW1596821, JUU1506857JUU15965452, HOI1596822It also pulls other policyid which contains different prefix(case:two different policyid merged in same filed). How to eliminate that idsExpected resultJUU1534322JUU1596832JUU1506857JUU15965452 Any help will be highly appreciated,ThanksSG |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2011-09-30 : 08:57:30
|
| Select policyid from policy where policyid like ‘JUU%’and policyid not like '%,%'If this is supposed to be an id field, why do you have more than one value per row?!? |
 |
|
|
memorykills
Starting Member
18 Posts |
Posted - 2011-09-30 : 13:03:04
|
| select policyIDfrom policywhere policyid like 'JUU%' and policyid not like '%,%'UNION ALLselect RIGHT(policyID, LEN(policyID) - patindex('%,%',policyID)-1)from policywhere policyid like '%, JUU%' and policyid like '%,%'UNION ALLselect LEFT(policyID, patindex('%,%',policyID)-1)from policywhere policyid like 'JUU%,%' |
 |
|
|
|
|
|
|
|