Results 1 to 8 of 8
  1. #1
    blacksaibot is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Jan 2010
    Posts
    34

    Formatting numbers to have a leading zero

    I have an INSERT query like so:
    Code:
    INSERT INTO table1 (column1, column2, column3, column4, column5)
    
    SELECT (field1, field2, field3, field4, field1 & "" && field2)
    
    FROM mastertable
    According to the format desired by a client, column5 from table1 needs to have field1 and field2 concatenated and represented as two-digit numbers if they're a one digit (has a leading zero).


    Is there a way to achieve this?

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Format(Field1, "00")
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    right("0" & field1 & field2, 2)

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    oh if you are trying to generated a four digit text string you could do

    right("0" & field1,2) & right("0" & field2, 2)

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Maybe:

    Format(Field1 & field2, "00")

    or

    Format(Field1, "00") & Format(Field2, "00")
    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.

  6. #6
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    he now has 1287340182734187230812 things to try!

  7. #7
    NTC is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Posts
    2,392
    just for the sake of completeness.... a number field type cannot have leading zeros. No way around that basic rule. So one is actually discussing a text field type......

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Also, why duplicating data?
    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. Replies: 8
    Last Post: 03-10-2014, 11:47 AM
  2. Formatting Numbers in Decimal Places
    By bigmatt911 in forum Queries
    Replies: 3
    Last Post: 12-20-2013, 12:46 PM
  3. Replies: 9
    Last Post: 12-05-2013, 11:48 AM
  4. need help with formatting negative numbers
    By orientalmed in forum Access
    Replies: 3
    Last Post: 03-06-2013, 01:24 PM
  5. Formatting numbers in a report
    By bullwinkle55423 in forum Reports
    Replies: 1
    Last Post: 11-09-2010, 01:12 PM

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