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.
3 1974
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.
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.
@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): - Public Function fFormatDigits(varDigitsToFormat) As Variant
-
Dim strDigitsToFormat As String
-
-
'If not a valid Number, get outta Dodge!
-
If Not IsNumeric(varDigitsToFormat) Then fFormatDigits = Null
-
-
'easier to initially work with a String
-
strDigitsToFormat = CStr(varDigitsToFormat)
-
-
'Search for a Terminating Null Character (Chr$(0)), if found strip it
-
If Right$(strDigitsToFormat, 1) = Chr$(0) Then
-
strDigitsToFormat = Left(strDigitsToFormat, Len(strDigitsToFormat) - 1)
-
End If
-
-
If Len(strDigitsToFormat) > 8 Then
-
fFormatDigits = Null
-
Else
-
fFormatDigits = Format(Val(strDigitsToFormat), "00000000")
-
End If
-
End Function
OUTPUT: - Debug.Print fFormatDigits(1)
-
00000001
- Debug.Print fFormatDigits(12)
-
00000012
- Debug.Print fFormatDigits(123)
-
00000123
- Debug.Print fFormatDigits(1234)
-
00001234
- Debug.Print fFormatDigits(12345)
-
00012345
- Debug.Print fFormatDigits(123456)
-
00123456
- Debug.Print fFormatDigits(1234567)
-
01234567
- Debug.Print fFormatDigits(12345678)
-
12345678
- Debug.Print fFormatDigits(123456789)
-
Null
- Debug.Print fFormatDigits(1234567 & Chr(0))
-
01234567
- ? fFormatDigits(12345678 & Chr(0))
-
12345678
P.S. - You can pass from 1 to 8 Digits to the Function.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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 ...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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,...
|
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...
| |