473,394 Members | 1,971 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Updating a column with additional digit

I've searched the forums with no success.

I have a column of data containing 7 digit and 8 digit numbers.

I would like to update all the 7 digit numbers and add a 0 in front of them so they become 8 digit numbers.

I have tried an update query and Find and Replace however I have had no success

iif(([line_item]) ="????????,"0???????,)


Any Suggestions?

Thanks.
Dec 15 '08 #1
3 1974
ambmil
3
as long as your fields only have 7 or 8 digits, and they all have to be 8 digits, try this:

iif(len([line_item])=7, "0" & [line_item]), [line_item])


you can also use a query:
update <<table>> set [line_item] = "0" & [line_item] where len([line_item]) < 8

If your values have several varying lengths, but must all be 8 digits, you would just run this query until it stops. Your field must be a text field for this to work.
Dec 15 '08 #2
Thank You.

Using:
iif(len([line_item])=7, "0" & [line_item]), [line_item])

I was able to find out that after my 7th digit, I had a Null Character.
Therefore the exact code didn't work.

Still trying to beat my head into getting this null character calculated.

...=7 & " ", as well as =7 & NULL, are not working.
Dec 15 '08 #3
ADezii
8,834 Expert 8TB
@ilikebirds
I hastily wrote a custom Function which will accept a Long Integer, or a Long Integer with a Terminating Null. It will strip the Null Terminator, if it exists, and should return the proper results as indicated by the demo code below. I leave it up to you to make sure that a SINGLE or DOUBLE is not passed to the Function (it will trap a non-numeric or String and return Null):
Expand|Select|Wrap|Line Numbers
  1. Public Function fFormatDigits(varDigitsToFormat) As Variant
  2. Dim strDigitsToFormat As String
  3.  
  4. 'If not a valid Number, get outta Dodge!
  5. If Not IsNumeric(varDigitsToFormat) Then fFormatDigits = Null
  6.  
  7. 'easier to initially work with a String
  8. strDigitsToFormat = CStr(varDigitsToFormat)
  9.  
  10. 'Search for a Terminating Null Character (Chr$(0)), if found strip it
  11. If Right$(strDigitsToFormat, 1) = Chr$(0) Then
  12.   strDigitsToFormat = Left(strDigitsToFormat, Len(strDigitsToFormat) - 1)
  13. End If
  14.  
  15. If Len(strDigitsToFormat) > 8 Then
  16.   fFormatDigits = Null
  17. Else
  18.   fFormatDigits = Format(Val(strDigitsToFormat), "00000000")
  19. End If
  20. End Function
OUTPUT:
Expand|Select|Wrap|Line Numbers
  1. Debug.Print fFormatDigits(1)
  2. 00000001
Expand|Select|Wrap|Line Numbers
  1. Debug.Print fFormatDigits(12)
  2. 00000012
Expand|Select|Wrap|Line Numbers
  1. Debug.Print fFormatDigits(123)
  2. 00000123
Expand|Select|Wrap|Line Numbers
  1. Debug.Print fFormatDigits(1234)
  2. 00001234
Expand|Select|Wrap|Line Numbers
  1. Debug.Print fFormatDigits(12345) 
  2. 00012345
Expand|Select|Wrap|Line Numbers
  1. Debug.Print fFormatDigits(123456) 
  2. 00123456
Expand|Select|Wrap|Line Numbers
  1. Debug.Print fFormatDigits(1234567)
  2. 01234567
Expand|Select|Wrap|Line Numbers
  1. Debug.Print fFormatDigits(12345678)
  2. 12345678
Expand|Select|Wrap|Line Numbers
  1. Debug.Print fFormatDigits(123456789)
  2. Null
Expand|Select|Wrap|Line Numbers
  1. Debug.Print fFormatDigits(1234567 & Chr(0))
  2. 01234567
Expand|Select|Wrap|Line Numbers
  1. ? fFormatDigits(12345678 & Chr(0))
  2. 12345678
P.S. - You can pass from 1 to 8 Digits to the Function.
Dec 16 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Sanjay Minni | last post by:
What is the datatype to be used for Primary Key columns for most optimised access given that - There will be a single column primary key only - The values will only be integers (but as...
6
by: Simon | last post by:
Hello, I am trying to update some varchar2 fields, which are storing dates. I am trying to set a 'to date' with the next minumum from date i.e from date | to date 01/01/1901 ...
6
by: Bill | last post by:
In an effort to improve the speed of queries against my main table, I'll be indexing a column whose data type is varchar(50). Would I be better off (better performance) if I changed the column's...
9
by: allenj | last post by:
DB2 UDB 7.2 WSE Fixpak 9 Linux Red Hat 7.3 I have some library code (written in Java, if that matters) that processes maintenance screens that are presented to the end-users as forms in a...
1
by: Terry | last post by:
Problem: ========= Unknown column appearing in federated tables. Description: ============ Local database (L) is an established 'federated' database, extracting values from multiple remote...
0
by: cwbp17 | last post by:
I'm having trouble updating individual datagrid cells. Have two tables car_master (columns include Car_ID, YEAR,VEHICLE) and car_detail (columns include Car_ID,PRICE,MILEAGE,and BODY);both tables...
14
by: el_sid | last post by:
Our developers have experienced a problem with updating Web References in Visual Studio.NET 2003. Normally, when a web service class (.asmx) is created, updating the Web Reference will...
33
by: bill | last post by:
In an application I am writing the user can define a series of steps to be followed. I save them in a sql database using the field "order" (a smallint) as the primary key. (there are in the range...
2
by: cccompton via DBMonster.com | last post by:
Greetings all. We recently upgraded from DB2 v8.2 to 9.1 FP1 and tested the AUTO_REORG functionality. As recommended by SAP, we scheduled the job REORGCHK_ALL weekly. This spews out an error...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.