IIF or Len Statement Help

G

golfinray

I have some school districts that are plain, in other words Malvern School
District, and I have some with 4 numbers and a dash in front of them, like
2043 - Hartford School District. The ones that have the numbers and dash I
would like to strip off and the others leave alone. I have tried several
combinations and have not been able to get it right. Thanks!!!!
 
B

Bob Barrows

golfinray said:
I have some school districts that are plain, in other words Malvern
School District, and I have some with 4 numbers and a dash in front
of them, like 2043 - Hartford School District. The ones that have the
numbers and dash I would like to strip off and the others leave
alone. I have tried several combinations and have not been able to
get it right. Thanks!!!!

1. Backup your database
2. Try this:
UPDATE districts
Set District = Mid([District],8)
WHERE Mid([District],6,1) = "-"

(to use this, switch your query to SQL View, paste it in, correct the
table and field names, and switch back to Design View to see how to do
this in the Design grid)
 
B

Bob Barrows

golfinray said:
I have some school districts that are plain, in other words Malvern
School District, and I have some with 4 numbers and a dash in front
of them, like 2043 - Hartford School District. The ones that have the
numbers and dash I would like to strip off and the others leave
alone. I have tried several combinations and have not been able to
get it right. Thanks!!!!

Oh wait, is your intent to leave the data alone and do this in a SELECT
statement? If so, the solution is similar:

Select Mid([District],8) As ShortDistrictName
From Districts
WHERE Mid([District],6,1) = "-"
 
J

John Spencer MVP

If the pattern is exactly 4 numbers, a space, a dash, and a space then try the
following as a calculated column in your query.

IIF([DistrictName] Like "#### - *",Mid([DistrictName],*),[DistrictName])

If you want to permanently remove the numbers and the dash, the above would
work in an update query as the new value for the field.

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Query Help 3
Query Problem Help! 4
Help Please 6
Please help - returning strings 7
IFF Function help please 5
Problem with percentages 2
Isnull with a filter problem 4
Syntax for IIf Len 4

Top