Avatar of Michael Dean
Michael Dean
Flag for United States of America asked on

convert number field to a text equivalent

So  i have a table that contains a field "product_Level" I want to build a make table query that will convert the number values to a name.

In other words :

product_level = 69  convert to   Product_levelText = Capital Directions
Product_level = 67  Convert to Product_levelText  = Portfolio Solutions.
.
.
.
.
.
.
Microsoft Access

Avatar of undefined
Last Comment
mbizup

8/22/2022 - Mon
mbizup

Do you mean a Make Table or Update query?

For an UPDATE:
UPDATE YourTable SET product_levelText = "Capital Directions"  WHERE Product_Level =69

Open in new window

UPDATE YourTable SET product_levelText = "Portfolio Solutions"  WHERE Product_Level =67

Open in new window

For a Make table query:


SELECT  Field1, Field2, ProductLevel "Portfolio Solutions" AS product_levelText  WHERE ProductLevel  = 67 INTO YourTable

Open in new window


SELECT  Field1, Field2, ProductLevel "Capital Directions" AS product_levelText  WHERE ProductLevel  = 69 INTO YourTable

Open in new window



You would need to run as many queries as number to text operations you have...

If there is some logic to how the numbers correlate to the text, you may be able to code a generic solution, otherwise you would need distinct queries for each number.
Jim Dettman (EE MVE)

Add another table to your database with the following:

tblProductLevels
Level - Number - Long
Description - Text

 now in your make table query, add this table to the query, join Level to your main record, then pull down the description field into what ever you need it for.

If this is a one time deal, you could also use the Replace() function as a definition for a column, but if you have a lot of them (more then a half dozen or so), you'd be better to use the table.

Your other option would be to call a function from the query, pass the level and return a description.  Then you could have as many If's/Case statements as you needed.

Jim.
Chris B

Or even leave the existing table as is if this is the way the data comes in and link it to JDettmans descriptor table for reporting. That way you retain flexibility if there are changes or additions in the future.

Chris B
Your help has saved me hundreds of hours of internet surfing.
fblack61
Michael Dean

ASKER
Why am I selecting Field1, Field2??
mbizup

>> Why am I selecting Field1, Field2??

Those are hypothetical field names.  Without knowing your table structure, I guessed that you may have other fields that need to be selected and added to your new table.
Michael Dean

ASKER
This is a one time thing, and the possible values are only 5..

69  = Capital Directions
24  = Portfolio
25  = integrated
26 = Strategic
59 = Alternative
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
mbizup

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.