472,980 Members | 1,869 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

update to parse out part of record

How can I write an update query that removes part of a field? Like if I
have a field with values such as 8/3/68 (a birthday obviously) and I need
to put values in a new column but I need everything after and including the
final / removed to end up with simply 8/3
Nov 12 '05 #1
3 4703
Ken,
Regardless of how the date is displayed, if the field is a Date/Time
datatype, the actual value is stored as a number.
Today's date, 9/10/2003, is stored as 37874.

Any valid date must include the month, day, and year values.
8/3 is NOT a valid date datetype.

There is no need for an update query.

To 'display' a date as 8/3 in a date field all you need do is set the
field's format property to
mm/dd

To do this in a query, you would use:
NewField:Format([DateField],"mm/dd")

In a form or report control:
=Format([DateField],"mm/dd")
make sure the name of the control is not the same as [DateField].

Just show it as I have indicated above, in a form, report, or query.
--
Fred

Please reply only to this newsgroup.
I do not reply to personal e-mail.
"Ken Bush" <KB****@csu.edu> wrote in message
news:hxK7b.408657$o%2.186111@sccrnsc02...
How can I write an update query that removes part of a field? Like if I
have a field with values such as 8/3/68 (a birthday obviously) and I need
to put values in a new column but I need everything after and including the final / removed to end up with simply 8/3

Nov 12 '05 #2
Er.. that was just kind of an example, not to be taken literally as such.
I guess that's my fault.

Let me try again.

Field1 has values such as

10_51_ER

I need to update Field2 to everything but the last _ and whatever follows
it, for example in this case it would be 10_51. Note that the values of
field1 may have less or more underscore seperators, but in any case I need
the last one and what follow to be removed.

fg******@att.net (Fredg) wrote in
<t7**********************@bgtnsc04-news.ops.worldnet.att.net>:
Ken,
Regardless of how the date is displayed, if the field is a Date/Time
datatype, the actual value is stored as a number.
Today's date, 9/10/2003, is stored as 37874.

Any valid date must include the month, day, and year values.
8/3 is NOT a valid date datetype.

There is no need for an update query.

To 'display' a date as 8/3 in a date field all you need do is set the
field's format property to
mm/dd

To do this in a query, you would use:
NewField:Format([DateField],"mm/dd")

In a form or report control:
=Format([DateField],"mm/dd")
make sure the name of the control is not the same as [DateField].

Just show it as I have indicated above, in a form, report, or query.
--
Fred

Please reply only to this newsgroup.
I do not reply to personal e-mail.
"Ken Bush" <KB****@csu.edu> wrote in message
news:hxK7b.408657$o%2.186111@sccrnsc02...
How can I write an update query that removes part of a field? Like if
I have a field with values such as 8/3/68 (a birthday obviously) and I
need to put values in a new column but I need everything after and
including

the
final / removed to end up with simply 8/3



Nov 12 '05 #3
If I understand you correctly you want to use Field1's data (10_51_ER)
to parse into Field2 (as 10_51).

If the final underscore is ALWAYS followed by 2 letters:
Update YourTable Set YourTable.Field2 = Left([Field1],len([Field1]-3))
Where [Field1] is not null;

However, if the characters after the final underscore can vary, (10_51_A or
10_51_ABCD),
AND you are using Access 2002 (or some versions of Access 2000) you can use:

UPDATE YourTable SET YourTable.Field2 =
Left([Field1],InStrRev([Field1],"_")-1)
WHERE YourTable.Field1) Is Not Null;

If you are using a previous version of Access (97, 95, 2) that does not have
the InStrRev() function, you'll need to write a user defined function to
find the final underscore position and return the wanted string.

Add the following function to a module:

Public Function Parse(strIn As String) As String
Dim intX As Integer
Dim intY As Integer
intX = InStr(strIn, "_")
If intX = 0 Then
Parse = strIn
Exit Function
Else
Do While intX <> 0
intY = intX + 1
intX = InStr(intY, strIn, "_")
Loop

Parse = Left(strIn, intY - 2)
End If

End Function
===

Then make an Update query:

Update YourTable Set YourTable.Field2 = Parse([Field1])
Where Field1 is not null.

--
Fred

Please reply only to this newsgroup.
I do not reply to personal e-mail.
"Ken Bush" <KB****@csu.edu> wrote in message
news:WiL7b.309340$cF.94367@rwcrnsc53...
Er.. that was just kind of an example, not to be taken literally as such.
I guess that's my fault.

Let me try again.

Field1 has values such as

10_51_ER

I need to update Field2 to everything but the last _ and whatever follows
it, for example in this case it would be 10_51. Note that the values of
field1 may have less or more underscore seperators, but in any case I need
the last one and what follow to be removed.

fg******@att.net (Fredg) wrote in
<t7**********************@bgtnsc04-news.ops.worldnet.att.net>:
Ken,
Regardless of how the date is displayed, if the field is a Date/Time
datatype, the actual value is stored as a number.
Today's date, 9/10/2003, is stored as 37874.

Any valid date must include the month, day, and year values.
8/3 is NOT a valid date datetype.

There is no need for an update query.

To 'display' a date as 8/3 in a date field all you need do is set the
field's format property to
mm/dd

To do this in a query, you would use:
NewField:Format([DateField],"mm/dd")

In a form or report control:
=Format([DateField],"mm/dd")
make sure the name of the control is not the same as [DateField].

Just show it as I have indicated above, in a form, report, or query.
--
Fred

Please reply only to this newsgroup.
I do not reply to personal e-mail.
"Ken Bush" <KB****@csu.edu> wrote in message
news:hxK7b.408657$o%2.186111@sccrnsc02...
How can I write an update query that removes part of a field? Like if
I have a field with values such as 8/3/68 (a birthday obviously) and I
need to put values in a new column but I need everything after and
including

the
final / removed to end up with simply 8/3


Nov 12 '05 #4

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

Similar topics

8
by: Jan van Veldhuizen | last post by:
The UPDATE table FROM syntax is not supported by Oracle. I am looking for a syntax that is understood by both Oracle and SqlServer. Example: Table1: id name city ...
1
by: oldandgrey | last post by:
I'm looking at producing an application that will allow multiple users to order multiple items/ parts from what would effectively be an online store. These users could be ordering several hundred...
1
by: Rolan | last post by:
Having tried various permutations of Before Update and well for that matter, After Update, OnExit, OnEnter, etc. and also Locked controls, I'm still unable to obtain the intended results. There are...
4
by: gj | last post by:
Hi, I'm trying to update a sql database from a web form using text boxes. I'm trying to learn C# on my own so I am at a complete loss. I created my sql connection, data adapter, dataset and data...
1
by: mursyidatun ismail | last post by:
Dear all, database use: Ms Access. platform: .Net i'm trying to update a record/records in a table called t_doctors by clicking da edit link provided in the database. when i ran through da...
11
by: Siv | last post by:
Hi, I seem to be having a problem with a DataAdapter against an Access database. My app deletes 3 records runs a da.update(dt) where dt is a data.Datatable. I then proceed to update a list to...
4
by: UKuser | last post by:
Hi Guys, I am trying to create an editable table of a MySQL query where every field can be updated. My example script is at: http://nana46.coconia.net/test4.php however I am currently getting...
2
by: Miro | last post by:
I will ask the question first then fumble thru trying to explain myself so i dont waste too much of your time. Question / Statement - Every mdb table needs a PrimaryKey ( or maybe an index - i...
29
by: gs | last post by:
let say I have to deal with various date format and I am give format string from one of the following dd/mm/yyyy mm/dd/yyyy dd/mmm/yyyy mmm/dd/yyyy dd/mm/yy mm/dd/yy dd/mmm/yy mmm/dd/yy
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.