?
Solved

SQL/Access insert zero into field/number string

Posted on 2007-08-06
4
Medium Priority
?
776 Views
Last Modified: 2013-11-05
I have a text string field in MS access. I am having problems ordering the field because of the numbers inserted in the string.

Example strings:
NU-C1
NU-C2
NU-C3
...
NU-C21
NU-C22.1


How can I write an sql/access code to adjust this to insert a zero in the string before a single digit. I was thinking something along the lines of a truncate to numbers then if length is =1... but I'm not sure how to pull it together.

Ideas?
Thanks!
0
Comment
Question by:bestiosus
  • 3
4 Comments
 
LVL 48

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 19639741
Hello bestiosus,

Without modifying the actual data, you could write a query to return you data sorted correctly. Something like this.....

SELECT Table2.Field1
FROM Table2
ORDER BY Table2.Field1, Mid([Field1],5);

This would return this....
      
NU-C1      
NU-C2      
NU-C21      
NU-C22.1      
NU-C3      


Regards,

Wayne
0
 
LVL 48

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 19639755
but that's probably not how you wan't it sorted....
0
 
LVL 48

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 19639790
Maybe this query would be better....

     SELECT Table2.Field1
     FROM Table2
     ORDER BY CDbl(Mid([Field1],5)), Table2.Field1;
0
 
LVL 4

Accepted Solution

by:
ki_ki earned 2000 total points
ID: 19639801
Here is how you can add a "0" to single digits:
UPDATE Table1 SET Table1.field =left(field,4) & "0" & right(field,1)
WHERE (((Len([field]))=5));

If you sort by Mid([Field1],5), you'll have problems with C22.1, C22.2, C22.3......
0

Featured Post

Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Suggested Courses

807 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