Results 1 to 2 of 2
  1. #1
    jrattner is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2012
    Posts
    1

    Exclamation Update Query: Breaking a Field into Several Fields

    Forums,

    I have a field within a table entitled "Material Description". This field contains information about our material:

    Example Value 1: 6-1/2X1.500-304LS
    Example Value 2: 6X.250-304LS
    Example Value 3: 4X.065-316LW

    However, I need to convert this field into two separate fields entitled, "Group" and "size" based on the its content. For example, the correct conversion of the examples above would be:

    Example 1:
    Group: SMT
    Size: 6.121.500

    Example 2:
    Group: SST
    Size: 6.250

    Example 3:


    Group: SWT
    Size: 4.065

    Rules:
    1. Group:
    • If the description ends in a "s" and the portion after the X is greater than or equal to .188 then group = "SMT".
    • If the description ends in a "s" and the portion after the X is less than .188 then group = "SST".
    • If the description ends in a "W" then the group = "SWT".


    2. Size: Numbers before the X need to be converted. For example, "1-1/4" becomes "1.14". But, the numbers after the X remain as is. The X disappears. The dash and all characters after it should be removed.

    Please let me know if you have any ideas. Figuring out how to convert the size is most perplexing.

    Thank you,

    JR

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Use string manipulation and conditional structures.

    The first break is fairly easy if the part at the end will always be 5 characters:
    PartA = Left([fieldname],Len([fieldname])-6)

    If there is always a single X, get the part that follows:
    NumPart = Mid(PartA, Instr(PartA,"X")+1)

    Group = "S" & IIf(Right([fieldname],1)="W","W", IIf(NumPart>=0.188,"M","S")) & "T"

    Now the size part - don't want 1/4 to become .25?
    Size = Replace(Replace(Replace(PartA,"-","."),"/",""),"X","")

    You can nest the expressions for PartA and NumPart for some very long expressions in query or write custom function that is called in the query.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. UPDATE query with many fields
    By Deutz in forum Queries
    Replies: 7
    Last Post: 08-23-2011, 05:53 PM
  2. Replies: 15
    Last Post: 10-14-2010, 12:22 PM
  3. Cant update fields when using a query
    By JohnBoy in forum Queries
    Replies: 4
    Last Post: 06-12-2010, 01:13 AM
  4. Replies: 1
    Last Post: 02-03-2010, 09:17 PM
  5. Replies: 1
    Last Post: 08-04-2008, 03:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums