SQL IIf Then Statement

Posted on 2007-08-06
Last Modified: 2013-11-05
I have a large table containing one field "Unit" that 50% of the units are 4-digit numbers and the other 50% are 5-digit numbers.   I need to add a zero to the left of the 4-digit numbers but do not want to add the zero to the 5-digit numbers. How would I accomplish this?  I am working in MS Access 97 but can use the SQL feature for updating this table.
Question by:deer777

    Author Comment

    Tried this in the Update mode of the Access query but it doesn't work

    IIf (Len[Unit] = 4, "0"+[Unit])
    LVL 142

    Accepted Solution

    IIf (Len[Unit] = 4, "0" & [Unit], [Unit])

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    In the previous article, Using a Critera Form to Filter Records (, the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
    In the article entitled Working with Objects – Part 1 (, you learned the basics of working with objects, properties, methods, and events. In Work…
    In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now