473,387 Members | 1,545 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Truncating a Field

Using Access 2000 I need to truncate the last few characters of a string
based on the presence of a dash (-). This dash is not always present and can
be followed by a variable number of numbers and/or letters. Ideally I'd like
to do this with an Update Query to create a new field with the truncated
information but I'm open to other options as well.

Example: Field contains 123456-789 I would like a new field that only
returns 123456

Thanks for the help!
Nov 13 '05 #1
7 10391
iif(Instr(1,[Field],"-")=0,[Field],Left([Field],Instr(1,[Field],"-")-1))

Coral G wrote:
Using Access 2000 I need to truncate the last few characters of a string
based on the presence of a dash (-). This dash is not always present and can
be followed by a variable number of numbers and/or letters. Ideally I'd like
to do this with an Update Query to create a new field with the truncated
information but I'm open to other options as well.

Example: Field contains 123456-789 I would like a new field that only
returns 123456

Thanks for the help!

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200510/1
Nov 13 '05 #2
It doesn't seem like a good idea to create another field in your table which
holds information that already exists in your table. You can select the
information upto the "-" using the InStr function. With table data =

123456-78910
12345678

Query =
SELECT
IIf(InStr([your_field],"-")-1<0,[your_field],Mid([your_field],1,InStr([your_field],"-")-1))
AS Expr1
FROM your_table;

results =
123456
12345678

If you did want yo add the data to another field, the following will work:
UPDATE your_table SET your_table.truncated_field =
Mid([your_Field],1,InStr([your_field],"-")-1)
WHERE (((your_table.your_field) Like "*-*"));

Regards,

Mark

"Coral G via AccessMonster.com" <u14591@uwe> wrote in message
news:5563642b9dd72@uwe...
Using Access 2000 I need to truncate the last few characters of a string
based on the presence of a dash (-). This dash is not always present and
can
be followed by a variable number of numbers and/or letters. Ideally I'd
like
to do this with an Update Query to create a new field with the truncated
information but I'm open to other options as well.

Example: Field contains 123456-789 I would like a new field that only
returns 123456

Thanks for the help!

Nov 13 '05 #3
I know it doesn't seem like a good idea, but that's what my boss asked for :)

I think she'll be ok with splitting it into two fields, so I tried the second
option you listed but it's giving me a compile error. It's saying the
problem is in the Mid Expression, not sure if I did something wrong. Any
advice? I'm a bit new to this stuff, so it's probably something simple I
imagine. This is what it looks like right now:

UPDATE Customers SET Customers.ID2 =
Mid([ID],1,InStr([ID],"-")-1)
WHERE (((Customers.ID) Like "*-*"));

Customers is the name of the Table, ID is the name of the field I'm working
with.

Mark wrote:
It doesn't seem like a good idea to create another field in your table which
holds information that already exists in your table. You can select the
information upto the "-" using the InStr function. With table data =

123456-78910
12345678

Query =
SELECT
IIf(InStr([your_field],"-")-1<0,[your_field],Mid([your_field],1,InStr([your_field],"-")-1))
AS Expr1
FROM your_table;

results =
123456
12345678

If you did want yo add the data to another field, the following will work:

UPDATE your_table SET your_table.truncated_field =
Mid([your_Field],1,InStr([your_field],"-")-1)
WHERE (((your_table.your_field) Like "*-*"));

Regards,

Mark
Using Access 2000 I need to truncate the last few characters of a string
based on the presence of a dash (-). This dash is not always present and

[quoted text clipped - 8 lines]

Thanks for the help!

Nov 13 '05 #4
I have changed my table and field names and this is working fine. Just out
of curiosity, are both ID and ID2 set to Text datatypes?

UPDATE Customers SET Customers.ID2 = Mid([id],1,InStr([id],"-")-1)
WHERE (((Customers.ID) Like "*-*"));

Mark

"Coral G via AccessMonster.com" <u14591@uwe> wrote in message
news:55644f607c4c6@uwe...
I know it doesn't seem like a good idea, but that's what my boss asked for
:)

I think she'll be ok with splitting it into two fields, so I tried the
second
option you listed but it's giving me a compile error. It's saying the
problem is in the Mid Expression, not sure if I did something wrong. Any
advice? I'm a bit new to this stuff, so it's probably something simple I
imagine. This is what it looks like right now:

UPDATE Customers SET Customers.ID2 =
Mid([ID],1,InStr([ID],"-")-1)
WHERE (((Customers.ID) Like "*-*"));

Customers is the name of the Table, ID is the name of the field I'm
working
with.

Mark wrote:
It doesn't seem like a good idea to create another field in your table
which
holds information that already exists in your table. You can select the
information upto the "-" using the InStr function. With table data =

123456-78910
12345678

Query =
SELECT
IIf(InStr([your_field],"-")-1<0,[your_field],Mid([your_field],1,InStr([your_field],"-")-1))
AS Expr1
FROM your_table;

results =
123456
12345678

If you did want yo add the data to another field, the following will work:

UPDATE your_table SET your_table.truncated_field =
Mid([your_Field],1,InStr([your_field],"-")-1)
WHERE (((your_table.your_field) Like "*-*"));

Regards,

Mark
Using Access 2000 I need to truncate the last few characters of a string
based on the presence of a dash (-). This dash is not always present
and

[quoted text clipped - 8 lines]

Thanks for the help!

Nov 13 '05 #5
Yay, now it works, I have no idea why though. Thanks Mark!

Mark wrote:
I have changed my table and field names and this is working fine. Just out
of curiosity, are both ID and ID2 set to Text datatypes?

UPDATE Customers SET Customers.ID2 = Mid([id],1,InStr([id],"-")-1)
WHERE (((Customers.ID) Like "*-*"));

Mark
I know it doesn't seem like a good idea, but that's what my boss asked for
:)

[quoted text clipped - 48 lines]

Thanks for the help!

--
Message posted via http://www.accessmonster.com
Nov 13 '05 #6
I have a follow up question to this. Basically what this does is dump the
truncated data into another field, but right now I have to create that field
before I run the query. This is fine for me, but other people are going to
use the query and I want to know if it's possible to have the new field
automatically inserted into the table to minimize the work they have to do.

Thanks for the input!

Coral G wrote:
Yay, now it works, I have no idea why though. Thanks Mark!
I have changed my table and field names and this is working fine. Just out
of curiosity, are both ID and ID2 set to Text datatypes?

[quoted text clipped - 9 lines]
>
> Thanks for the help!

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200510/1
Nov 13 '05 #7
I'm no expert with table definition SQL's but as far as I know, you would
need to first run the Definition SQL and then run the UPDATE SQL.
Something like : alter table [customers] add column [ID3] string (50);

This will add another field to the table called ID3 which would be of a text
datatype and a field length of 50.

Then you could run your UPDATE query.

Regards,

Mark

"Coral G via AccessMonster.com" <u14591@uwe> wrote in message
news:55a38bdab6e23@uwe...
I have a follow up question to this. Basically what this does is dump the
truncated data into another field, but right now I have to create that
field
before I run the query. This is fine for me, but other people are going
to
use the query and I want to know if it's possible to have the new field
automatically inserted into the table to minimize the work they have to
do.

Thanks for the input!

Coral G wrote:
Yay, now it works, I have no idea why though. Thanks Mark!
I have changed my table and field names and this is working fine. Just
out
of curiosity, are both ID and ID2 set to Text datatypes?

[quoted text clipped - 9 lines]
>>
>> Thanks for the help!

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200510/1

Nov 13 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Guinness Mann | last post by:
I'm running SQL Server 2K (sp3a) and when I run the following query (in query analyzer): SELECT id, LEN(ForeignWord) as Length, ForeignWord FROM Words WHERE Language ='Thai' and...
1
by: Richard Coutts | last post by:
I have two select queries, "qryJobSpecsAlwaysList" and "qryJobSpecsBySchedCat," that list some fields, including a Memo field called "Description" that can contain text values that can be 500...
4
by: qazmlp | last post by:
Can anybody comment(& suggest improvements) on the following implementation that is for truncating the character buffer contents to the desired length? Truncating char array void...
5
by: VISHNU VARDHAN REDDY UNDYALA | last post by:
Hello, Can someone over here help me in truncating a float variable. I mean if PI=3.14159 ...How can I get to read the first two or first three decimal values with out rounding them. Any...
1
by: Jitesh Sinha | last post by:
Hi, I am running Windows 2003/ IIS 6.0. I was stuck with rather a abnormal behaviour of System.Web.mail class. It was truncating the message body after 3,071 character. The code i was testing...
3
by: rangermccoy | last post by:
Hello there, What are the best php/c libraries for handling media including images, video, and music? I would like to manipulate media dfiles, including watermarking, thumbnailing,...
17
by: tommy | last post by:
Hi all, I' m adding strings to some fields in my table via Access. The strings sometimes have trailing spaces and I really need to have it that way, but Access truncates trailing spaces. How can...
21
by: Jenn | last post by:
I have a memo field in a report that is truncating at 255 characters. I've tried the following w/no success: 1. Grow/Shrink option is yes. 2. "Group By" changed to "first". 3. "Group by" changed to...
2
by: DThreadgill | last post by:
I am pulling data into Access directly from a SQL Server (ODBC Connection). The properties of the field in question is set to memo. I'm making a query and joining to another stand-alone table in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.