How to set edit mask where zero means 0 and not any other number? - string-formatting

Situation:
Character 0 has special meaning in number display formats. My code picks date on certain conditions and make display format for another edit field (column in DW) for example 1905 where 19 is last 2 digits of current year and 05 is the current month + "-" + "####" so final display format that i want to set becomes like 1905-####.
Problem:
The zero in 1905 shows up in the target edit field (column) as 19 5. There is space shown at the location where 0 resides. The final result of the edit mask 1905-#### shows in edit field as 19 5- and cursor points exactly after digit 9 which i dont want.
Expecting:
I want to have the display format as "1905- " and keyboard cursor pointing after dash '-' for remaining 4 digits entry.
Question:
How to set number display format or edit mask to ignore special meaning of 0 and take 0 as digit zero and not as any other number?
For example this is how i set mask for Trans_ID column which is string type column.
dw_1.Object.Trans_ID.EditMask.Mask = Right(String(Date(dw_1.Object.DOB[1]), "YYYY"),2) + String(Date(dw_1.Object.DOB[1]), "MM") + "-####"
PowerBuilder v12.5

Try
string(month(today()), '00')
or, for the whole string
Right(String(Date(dw_1.Object.DOB[1]), "YYYY"),2) + String(month(Date(dw_1.Object.DOB[1]), "00") + "-####"

Related

Invalid formula - Operator "+" doesn't support TEXT + NUMBER. Operator "+" supports NUMBER + NUMBER

This was working last week but now it has an error like this:
Invalid formula - Operator "+" doesn't support TEXT + NUMBER. Operator "+" supports NUMBER + NUMBER
Current formula:
COUNT_DISTINCT(CASE
WHEN First Duration+Second Duration<=24 THEN New ID
ELSE NULL
END ) / COUNT_DISTINCT(CASE
WHEN First Duration IS NULL THEN NULL
WHEN Second Duration IS NULL THEN NULL
ELSE New ID
END )
I can only recommend checking that the First Duration and Second Duration dimensions are fields in the type number format. Otherwise, you can change it manually or create a new field to format the text dimension into a number.
I had problems where a field of type number or date, after a database update, was interpreted by Google Data Studio in text format. Apparently your formula doesn't have any syntax errors, only the dimensions used don't seem to follow the recommended format.

Formula to write milliseconds in hh:mm:ss.000 format gives wrong values

I'm trying to convert duration in one column which is written in milliseconds (Ex: 600,2101,1110....) to hh:mm:ss.000 format(Ex:00:00:00.600, 00:00:02.101...) using the below formula in google spreadsheets:
=CONCATENATE(TEXT(INT(A1/1000)/86400,"hh:mm:ss"),".",A1-(INT(A1/1000)*1000))
It gives correct values for almost all , but one type of values which is durations having '0' as their second digit (Eg: 2010,3056,1011).
When 0 is the second digit , the after decimal value in hh:mm:ss.000 is rounded to the third digit and 0 is ignored (Example row 1 and 2 in below table). But for other durations it gives right value(row 3).
I need a formula that works well on all type of values i.e 1080 → 00:00:01.080 and not 00:00:01.80 .
Can someone please help with this.
Duration in milliseconds
hh:mm:ss.000 format
1080
00:00:01.80 (wrong)
2010
00:00:02.10 (wrong)
1630
00:00:01.630 (correct)
try:
=INDEX(IF(A2:A="",,TEXT(A2:A/86400000, "hh:mm:ss.000")))

Adding the value in column of SQL Server 2012

I need to add two zero in POS data to make it 14th character numbers because TV UPC has 14th character numbers UPC.
For example
Table 1
POS UPC
------------
123456789012
Table 2
TV UPC
--------------
00123456789012
I have to make it POS UPC 14 character number by adding two zero at the beginning of the number to compare exact match.
Prefix the number with 14 0s and select 14 characters from right which will give you desired output
DECLARE #Number varchar(100)='123456789012'
SELECT RIGHT('00000000000000'+#Number,14)
Output
00123456789012
Replace variable with your column name.
Fiddle here : http://sqlfiddle.com/#!3/9f1d32/1

Replace values only if they are different

I have a vcf file like this:
http://www.1000genomes.org/node/101
Here's the example from that site:
##fileformat=VCFv4.0
##fileDate=20090805
##source=myImputationProgramV3.1
##reference=1000GenomesPilot-NCBI36
##phasing=partial
##INFO=<ID=NS,Number=1,Type=Integer,Description="Number of Samples With Data">
##INFO=<ID=DP,Number=1,Type=Integer,Description="Total Depth">
##INFO=<ID=AF,Number=.,Type=Float,Description="Allele Frequency">
##INFO=<ID=AA,Number=1,Type=String,Description="Ancestral Allele">
##INFO=<ID=DB,Number=0,Type=Flag,Description="dbSNP membership, build 129">
##INFO=<ID=H2,Number=0,Type=Flag,Description="HapMap2 membership">
##FILTER=<ID=q10,Description="Quality below 10">
##FILTER=<ID=s50,Description="Less than 50% of samples have data">
##FORMAT=<ID=GT,Number=1,Type=String,Description="Genotype">
##FORMAT=<ID=GQ,Number=1,Type=Integer,Description="Genotype Quality">
##FORMAT=<ID=DP,Number=1,Type=Integer,Description="Read Depth">
##FORMAT=<ID=HQ,Number=2,Type=Integer,Description="Haplotype Quality">
#CHROM POS ID REF ALT QUAL FILTER INFO FORMAT NA00001 NA00002 NA00003
20 14370 rs6054257 G A 29 PASS NS=3;DP=14;AF=0.5;DB;H2 GT:GQ:DP:HQ 0|0:48:1:51,51 1|0:48:8:51,51 1/1:43:5:.,.
20 17330 . T A 3 q10 NS=3;DP=11;AF=0.017 GT:GQ:DP:HQ 0|0:49:3:58,50 0|1:3:5:65,3 0/0:41:3
20 1110696 rs6040355 A G,T 67 PASS NS=2;DP=10;AF=0.333,0.667;AA=T;DB GT:GQ:DP:HQ 1|2:21:6:23,27 2|1:2:0:18,2 2/2:35:4
20 1230237 . T . 47 PASS NS=3;DP=13;AA=T GT:GQ:DP:HQ 0|0:54:7:56,60 0|0:48:4:51,51 0/0:61:2
20 1234567 microsat1 GTCT G,GTACT 50 PASS NS=3;DP=9;AA=G GT:GQ:DP 0/1:35:4 0/2:17:2 1/1:40:3
After the header lines, each line has fields that contain genotypes starting with the 10th field. The 10th field is below the NA0001 heading; the 11th field is genotype NA0002, etc. I have a file with 123 different genotypes, so going from position 10 to 133 (NA0001 until NA0123). What is shown in these fields can be 0/0, 0/1, 0/2 .... till 8/9 for instance. Now I want to replace all the non-equal ones. So I would like to keep 0/0, 1/1, 2/2, etc. And replace 0/1, 0/2, 1/2, 4/5, 4/6 etc by ./.
I would like to write this in a C script. Thought about using sed y/regexp/replacement/ but no idea how to write all those unequal values in a regular expression. And on other positions in the file there could also be these values, so really only positions 10 till 133 should be replaced. And it needs to be replaced; I will be needing the rest of the file with the new values.
Hope it is clear. Anyone any idea how to do this?
This regex should do what you want: \s(\d)[|\/](?!\1)\d: Replace matches with ./.:
Breakdown:
\s(\d) matches a space followed by a single digit, capturing the digit in capture group #1
[|\/] matches a pipe or slash (since it seems that the VCF format allows either)
(?!\1)\d uses a negative lookahead to ensure that the next character is not the same as capture group #1, and matches the digit
Caveats:
I matched a leading space and trailing : to try to ensure it matches only the intended values. I couldn't work out a good way to limit it to fields 10 and after.
Example using perl:
perl -pe 's#\s(\d)[|/](?!\1)\d:# ./.:#g' testfile.vcf > testfile_afterchange.vcf
Note: I used # as the delimiter to avoid having to escape the / characters in the regex.

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.

Resources