Results 1 to 8 of 8
  1. #1
    Bertrand82 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Sep 2012
    Posts
    48

    Convert number to text

    I have a query that contants a field with numbers.

    I would like the query to replace the numbers with text. eg.

    25 = North America
    60 = Europe
    90 = Asia



    Should i use the expression builder if yes, whats the code?

    Br Bertrand

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    Only 3 items?

    Try:

    Switch(fieldname=25,"North America", fieldname=60,"Europe", fieldname=90, "Asia")

    Alternatively, have a table of this data and include that table in query by joining on the number fields.
    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.

  3. #3
    Bertrand82 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Sep 2012
    Posts
    48
    Switch("fieldname"=25;USA)

    gives me data type mismatch in criteria expression

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    Use your actual field name instead of fieldname. Is it a number or text type? Literal strings must be in quote marks per my example: "USA"
    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.

  5. #5
    Bertrand82 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Sep 2012
    Posts
    48
    I have realized that this is a little bit more complicated than first thougt and will therefor mark this thread as solved. thanks anyway,

    Br

  6. #6
    Bertrand82 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Sep 2012
    Posts
    48
    Im back


    Below you find the code from my union Query. The field "Company" within table GI brazil/GI USA/GI Korea contains numbers 25, 60, and 90.

    I would like the query to replace the numbers with 25 = USA, 60 = Brazil, 90 = Korea.

    Can someone please insert the correct code so I can copy and paste in SQL view?

    Br Bertrand


    SELECT [GI brazil].Company, [GI brazil].ID, [GI brazil].First_name, [GI brazil].Family_name, [GI brazil].[Hire_ date]
    FROM [GI brazil];
    UNION ALL SELECT [GI USA].Company, [GI USA].ID, [GI USA].First_name, [GI USA].Family_name, [GI USA].[Hire_ date]
    FROM [GI USA];
    UNION ALL SELECT [GI KOREA].Company, [GI KOREA].ID, [GI KOREA].First_name, [GI KOREA].Family_name, [GI KOREA].[Hire_ date]
    FROM [GI KOREA]
    ORDER BY Company, Family_name, First_name;

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    Why do you have 3 tables GI brazil/GI USA/GI Korea? I don't understand data structure.

    If you want to provide file for analysis, follow instructions at bottom of my post.
    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.

  8. #8
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Your structure is not normalized. What would you do if you had to add another country - say France?? Currently, you would have to add another table, modify your queries, forms and reports.

    If you structure was normalized, you would have one table to hold the names, hire date and company, with an additional field for the country.

    So lets call the table "tblGI". And the fields would be

    Code:
    ID  -  Autonumber (PK)  
    First_name  - Text
    Family_name - Text
    Company - Text ( or Long - FK to another table)
    Hire_date - Date/Time  (no space in the name)
    Country - Text ( or Long - FK to another table)
    Then your query would look like
    Code:
    SELECT tblGI.ID, tblGI.Company, tblGI.First_name, tblGI.Family_name, tblGI.Hire_date, tblGI.Country
    FROM GI
    ORDER BY tblGI.Company, tblGI.Family_name, tblGI.First_name;
    If you wanted to add someone from another country, it would be a simple process, just add the data

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

Similar Threads

  1. Convert Text to Number
    By Jerseynjphillypa in forum Import/Export Data
    Replies: 7
    Last Post: 05-09-2012, 12:45 PM
  2. How to Convert string to Number?
    By taimysho0 in forum Programming
    Replies: 1
    Last Post: 02-24-2012, 01:57 PM
  3. Replies: 2
    Last Post: 11-22-2011, 11:45 AM
  4. Convert number to fixed length text field
    By tpcervelo in forum Queries
    Replies: 1
    Last Post: 08-02-2010, 07:26 PM
  5. Number convert to date
    By Argus in forum Programming
    Replies: 1
    Last Post: 08-05-2009, 02:21 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