Format field for 3 numerical digits with optional letter - database

I have a very large list of assets all with room numbers. All room number are 3 digits. Room number on the bottom floor begin with leading zeros (001, 002, etc). However, some rooms have letters after them (020A, 020B).
How can I format my field in Microsoft Access to display leading zeros but also accept that some rooms have a letter after the 3 digits?

A text formatted field will display any entered data as a string literal, i.e. no matter what combination of numbers and letters you enter it will keep those data as typed. So 001 and 020A would both be accepted.

Related

Weird string formatting with 2 vs 4 decimal places in currency field

I have the following piece of code. I want to format numbers with string templates. One variable has 2 decimal places, the other 4 decimal places but they represent the same number 50000 (fifty thousand).
The first number is correctly formatted (German representation) 50.000,00, the other one however is formatted as 5 million 5.000.000,00!
DATA: lv_p2 TYPE p LENGTH 9 DECIMALS 2,
lv_p4 TYPE p LENGTH 14 DECIMALS 4.
START-OF-SELECTION.
lv_p2 = '50000'.
lv_p4 = lv_p2.
SET COUNTRY 'DE'.
"This is correctly formatted as 50.000,00
WRITE |{ lv_p2 NUMBER = ENVIRONMENT CURRENCY = 'EUR' }|.
"This is on the other hand interpreted as five million! 5.000.000,00
WRITE |{ lv_p4 NUMBER = ENVIRONMENT CURRENCY = 'EUR' }|.
Is this documented somewhere? What am I doing wrong here?
EDIT:
It looks like the problem is with the addition CURRENCY. If I don't use it, then the number is correctly formatted.
WRITE |{ lv_p4 NUMBER = ENVIRONMENT }|.
or WRITE |{ lv_p4 NUMBER = ENVIRONMENT DECIMALS = 2 }|.
Anyway looks like some kind of a bug.
I believe this behaviour is documented.
ABAP Documentation - WRITE, format_options - CURRENCY cur
When CURRENCY is added:
"For data objects of type p, the decimal places determined by the
definition of the data type are ignored completely. Independently of
the actual value and without rounding, decimal separators and
thousands separators are inserted between the digits in the places
determined by cur."
Shortly: if CURRENCY is added (by WRITE), the number of decimal places is determined by the currency (in this case EUR has 2 decimal places), so the value 50.000,0000 will be 5.000.000,00. Same length (9 digits) only the number of decimals will be different.

Pattern that restricts user to enter special characters for first character

I have a requirement for an input field that should allow numbers, alphabets, and special characters like #,$,%,^ etc. But with only one condition the first character that I enter in the text box should not be a special character.
Example:
#Test123 --Invalid character
Test#123 --Valid character
T#est123% --Valid character
I tried this
ng-pattern="/^([a-zA-Z0-9]+)([a-zA-Z0-9 &()_+#&\-=\\|,.\/?\s]+)$/"
But not working.
Try this one
ng-pattern="/^[a-zA-Z0-9]+[^]*$/"
[a-zA-Z0-9]+ means one of alphabet or number and
[^]* means everything

Lex/Flex - Split the phone number Up?

I am making a program which got to split the phone-number apart, each part has been divided by a hyphen (or spaces, or '( )' or empty).
Exp: Input: 0xx-xxxx-xxxx or 0xxxxxxxxxx or (0xx)xxxx-xxxx
Output: code 1: 0xx
code 2: xxxx
code 3: xxxx
But my problem is: sometime "Code 1" is just 0x -> so "Code 2" must be xxxxx (1st part always have hyphen or a parenthesis when 2 digit long)
Anyone can give me a hand, It would be grateful.
According to your comments, the following regex will extract the information you need
^\(?(0\d{1,2})\)?[- ]?(\d{4,5})[- ]?(\d{4})$
Break down:
^\(?(0\d{1,2})\)? matches 0x, 0xx, (0xx) and (0x) at he beggining of the string
[- ]? as parenthesis can only be used for the first group, the only valid separators left are space and the hyphen. ? means 0 or 1 time.
(\d{4,5}) will match the second group. As the length of the 3rd group is fixed (4 digits), the regex will automatically calculate the length of the Group1 and 2.
(\d{4})$ matches the 4 digits at the end of the number.
See it in action
You can the extract data from capture group 1,2 and 3
Note: As mentionned in the comments of the OP, this only extracts data from correctly formed numbers. It will match some ill-formed numbers.

How to add leading zeros to decimal value in tsql

i have weight column in a table where weight must be inserted with following format '09.230'. Weight column is of varchar type. so value from front end comes as '9.23' it should get converted to above mentioned format i.e.(09.230). I am able to add trailing zero but adding leading zero is a problem.
This is what i have done to add trailing zero
CAST(ROUND(#Weight,3,0) AS DECIMAL (9,3))
Suppose #Weight = 6.56 output with above comes out be '6.560' but output wanted as '06.560'.
RIGHT('0'+ CONVERT(VARCHAR, CAST(ROUND(#Weight,3,0) AS DECIMAL (9,3))), 6)
This
takes your expression,
converts it to a varchar (retaining the trailing zeros, since the source data type was decimal),
adds a 0 in front of it, and
trims it to 6 characters by removing characters from the front, if needed (e.g. 012.560 -> 12.560, but 06.560 -> 06.560).
Do note, though, that this only works for numbers with at most two digits before the decimal point: 100.123 would be truncated to 00.123!

Character Width of Number Values in TSQL?

MSSSQL 2008.
I have 3 Ints, 1 BigInt, 1 Float, and 1 DateTime value.
I am trying to concatenate them all into a single Char value and not lose any precision, which should let me create a single unique long value.
What are would the total character width be if I could make all of the numbers Chars and then combine them? The DateTime should go to MMDDYYHHMMSS.
Thanks.
INTs can be up to 10 digits.
BIGINTs can be up to 19 digits.
Floats could be anything. They have 38 digits of precision, but could be an enormous number with limited precision (1.79E + 308). You don't want that as a string. If your application has knowledge of what the actual range of values the float could be, you could make an application decision for a specific number of digits.

Resources