In an old application, I have a table (Paradox DB) that contains a numeric "number" field.
The user can enter the "number" in two ways:
Example:
1- 123
or
2- 000123
I have not yet found the trick to record a recording starting with zeros.
How to save zeros in DB as: 000123 please?
Thank you for your help.
You cannot store leading zeros in a numeric column. If you need to retain leading zeros then you must use a text column, or perhaps a separate column to contain the number of leading zeros.
This isn't to do with storage, it is to do with display. If the database is that old the value is probably stored internally as two bytes, and so 'leading zeros' is meaningless in terms of storage. The alternatives are to store data as a string (which happens to contain numeric digits) or format the (text) display using standard formatting routines.
Related
Some segments in HL7v2 can be repeating, but what if one of those repetitions is blank? Should the blank repetition be removed? Or should they remain?
For example, in the below extract PID.13 is a repeating field, but the first repetition is blank. It does not even contain "" (empty string).
PID|||A123456789^^^555^PI||Data^Test^^^Mr||19500101|M|||123 Test Road^Testington^^^AA1 2AA||~07778895566|||M|||||||||||||""|||
The PID-13 field has been deprecated as of v2.7 and should no longer be used. Use PID-40 instead.
PID-13 is a special case because the first occurrence has a special meaning, so if there are multiple field repetitions then you shouldn't remove the first one even if it isn't populated. For other fields which don't have documented special cases, you can safely delete empty field occurrence without changing the meaning of the message.
Please refer to this answer.
There are two things needs to be understood.
First:- Empty/blank/null value is also a value. Blank repetitions should not be removed.
Following is what specifications (2.3.2.4 Repetition Separator) say:
2.3.2.4 Repetition Separator.
The repetition separator is used in some data fields to separate multiple occurrences of a field. It is used only where specifically authorized in the descriptions of the relevant data fields. The character that represents the repetition separator is specified for each message as the second character in the Encoding Characters data field of the MSH segment. Absent other considerations it is recommended that all sending applications use '~' as the repetition separator. However, all applications are required to accept whatever character is included in the Message Header and use it to parse the message.
Yes; it does not clearly say anything about removing or keeping empty sub-components. Yes, it neither specifically say that empty value is also a value nor the opposite. I fail to find it in other parts of specifications as well.
To come to the conclusion, we need to move to second thing.
Second:- The sequence of repetition values may also be important. This sequence will change if empty values are removed. This may also change the meaning of the value.
Let us take an example of PID.13 you mentioned in the question.
This field contains the patient's personal phone numbers. All personal phone numbers for the patient are sent in the following sequence. The first sequence is considered the primary number (for backward compatibility). If the primary number is not sent, then a repeat delimiter is sent in the first sequence.
As you can see above, empty value for first sub component tells you that "there is no primary number available for patient". By removing empty value, you are actually putting "secondary number" in place of primary number which may be wrong depending on your use case or implementation.
Other example of PID.3:
This field contains the list of identifiers (one or more) used by the facility to uniquely identify a patient (e.g., medical record number, billing number, birth registry, national unique individual identifier, etc.).
As you can see, by removing empty values in-between changes the meaning of identifier.
I will still prefer clear reference from specifications, but based on what said above, I will avoid removing empty values.
I am storing phone numbers in the database in the user model in various formats. All the followings are possible.
+306974135662, 306974135662, 30 6974135662
Then from the front-end, I am getting a specific format that has the plus sign and no spaces.
+306974135662
I want to write a mongoid query that matches all the above formats. Is that possible?
User.where(phone: params[phone])
should return all 3 users with phone numbers +306974135662, 306974135662, and 30 6974135662
Option 1: store phone numbers as they are entered, use regular expressions for matching.
Option 2: store phone numbers as they are entered in one field. In another field store canonicalized representations of the phone numbers (the second one in your example). Match against the canonicalized representation.
The second option costs additional disk space, memory and pre-processing but allows queries to be simpler and faster.
This question already has answers here:
Query is ignoring string (non numeric) value
(2 answers)
Closed 5 months ago.
I am working on some data where i have to import the raw data from sheet Prepaid to the Master sheet but am seeing that certain number cells dont get imported like in cell B18 in sheet named Master. If I convert the raw data cell to number it works but it converts 11892667013478301 to 11892667013478300 leading to a mismatch. Is this is a size restriction on the number
Sheet is below
https://docs.google.com/spreadsheets/d/12y5h6NYArpEctQ2FD-AXJrqZcQydnEd5BjrOALMJEGI/edit?usp=sharing
From QUERY docs:
In case of mixed data types in a single column, the majority data type determines the data type of the column for query purposes. Minority data types are considered null values.
Since most values in your column end with two 0s, they don't reach the digit limit of 15, and are treated as numbers. The values that reach 15 digits are treated as string values, and since those are a minority in the column, they are considered null values.
To avoid this, you can force all values in the column to be treated as strings via TO_TEXT, and apply the QUERY to that.
=QUERY(ARRAYFORMULA(TO_TEXT(Prepaid!E:F)),"select * where Col1 is not null")
I'll delete my other answer, since yes, the issue seems to be that you are hitting the maximum number of significant digits, 15, for a number in Google Sheets. You can prove this by tring to add any small number to any of your (numeric) cells in Prepaid!F - the number doesn't increase, since it can't display any more significant digits.
The majority of your values are 15 signifcant digits plus two zeroes on the end. But F18 and F28 end in 01, not 00, so they are treated as strings. Forcing them to a number "discards" the last two significant digits, making them 00.
Perhaps the easiest answer for you is to force all of columns E and F to be text strings, rather than numeric values, and then they can all be dealt with equally, such as running queries against them.
Let me know if this helps at all.
I have a view where there is a column displayed numeric values. Earlier the field which displayed this numeric value was of type text, but later I changed it to Number. As I want the column to display this numeric value with 3 decimal places, I updated the column properties to display 3 decimal places. Now the new documents show the column with 3 decimal places, but the older documents still do not show 3 decimal places.
Is there any function that I can use to make the number display 3 decimal places?
If the value is 1, then it must show 1.000, if 0.8 then 0.800.
Change your column formula to
#ToNumber(YourField)
This way old values gets converted to a number and will be shown with 3 decimal places too.
YOu could also either write an agent that changes the field type of that specific field in all document to number, or you could use a tool like NoteMan.Editor (from MartinScott) or scanEZ (from Ytria) to do the same. As a developer/admin, you should have at least one of those tools, preferably both.
I blogged about them a while back, if you want to learn more:
http://blog.texasswede.com/stuff-i-use-every-day-siued-noteman/
http://blog.texasswede.com/my-favorite-tools/
I don't work for either of the companies, I am just a happy user of their tools.
This question already has answers here:
Query is ignoring string (non numeric) value
(2 answers)
Closed 5 months ago.
I have =query(importrange(...);"select * where Col1>' '") formula in my spreadsheet.
Importrange() by itself works ok, loading all the cells from source spreadhseet exactly as they are.
But Col7 contains few text cells, but mostly numbers, and when query() is applied -- numbers are kept as they are, but text is replaced with blank.
I've tried adding options no_format at the end of the query, with no difference.
Here's the contents of Col7, first line gets replaced with blank:
free
41,25
34,25
34,25
48,25
41,25
QUERY won't return columns with mixed data types by design:
In case of mixed data types in a single column, the majority data type
determines the data type of the column for query purposes. Minority
data types are considered null values.
The workaround will depend on how you want to use your data afterwards, and what compromises you would be willing to make. For example you could fairly easily convert the entire dataset into text strings, so that everything will be retained, but then all your numbers will be text strings as well.
If you needed to retain numbers as numbers, often the best bet will be to ImportRange the entire dataset somewhere in your spreadsheet (could be on a hidden sheet), and then use an alternative to QUERY on that (namely FILTER).
You can use vlookup for the columns that need to be a mixed data type. Query the unique row identifier and then vlookup the rest. I often use the following formula:
=arrayformula(if(isblank(A:A), "", vlookup(A:A, search_range, col_index, FALSE)))
Change the format of the whole column to plain text.
The numbers will still read as numbers, and the minority text values will retain their text values. Nothing will be counted as null.