I'm merging 2 fields into one value. I'm also replacing dots with commas with the below query.
REPLACE(CAST(testmin as varchar)+'-'+ CAST(testmax as varchar), '.', ',') AS Testvalue
This works a a charm as long as testmin isn't zero. But when it's zero that's the result I get.
As example I have
testmin 0,00
testmax 100
With the above query the the query returns 0.
If I change testmin to 1 then the query returns the correct value 1-100.
Any ideas on why it is like this?
Have you tried using CONCAT instead of '+' ?
Related
Probably a really easy solution.
I'm working with a sheet that has a simple division of two numbers to return the difference as a percentage. In this case: =O12/K12
Now if O12 and K12 are empty the cell returns a value of 0.00%. How can I change the formula so it just stays blank if there is no data in O12 and K12 please?
Any help would be amazing!
Thanks
Ryan
This happens because the empty string in a math formula is parsed to zero.
To avoid this, you could check if both are numbers before:
=IF(AND(ISNUMBER(O12),ISNUMBER(K12)),O12/K12,)
What it means: if O12 and K12 are numbers, calculate the division. If not, return an empty string (blank).
try:
=IFERROR(1/(1/(O12/K12)))
I'd need to split or extract only numbers made of 8 digits from a string in Google Sheets.
I've tried with SPLIT or REGEXREPLACE but I can't find a way to get only the numbers of that length, I only get all the numbers in the string!
For example I'm using
=SPLIT(lower(N2),"qwertyuiopasdfghjklzxcvbnm`-=[]\;' ,./!:##$%^&*()")
but I get all the numbers while I only need 8 digits numbers.
This may be a test value:
00150412632BBHBBLD 12458 32354 1312548896 ACT inv 62345471
I only need to extract "62345471" and nothing else!
Could you please help me out?
Many thanks!
Please use the following formula for a single cell.
Drag it down for more cells.
=INDEX(TRANSPOSE(QUERY(TRANSPOSE(IF(LEN(SPLIT(REGEXREPLACE(A2&" ","\D+"," ")," "))=8,
SPLIT(REGEXREPLACE(A2&" ","\D+"," ")," "),"")),"where Col1 is not null ",0)))
Functions used:
QUERY
INDEX
TRANSPOSE
IF
LEN
SPLIT
REGEXREPLACE
If you only need to do this for one cell (or you have your heart set on dragging the formula down into individual cells), use the following formula:
=REGEXEXTRACT(" "&N2&" ","\s(\d{8})\s")
However, I suspect you want to process the eight-digit number out of all cells running N2:N. If that is the case, clear whatever will be your results column (including any headers) and place the following in the top cell of that otherwise cleared results column:
=ArrayFormula({"Your Header"; IF(N2:N="",,IFERROR(REGEXEXTRACT(" "&N2:N&" ","\s(\d{8})\s")))})
Replace the header text Your Header with whatever you want your actual header text to be. The formula will show that header text and will return all results for all rows where N2:N is not null. Where no eight-digit number is found, null will be returned.
By prepending and appending a space to the N2:N raw strings before processing, spaces before and after string components can be used to determine where only eight digits exist together (as opposed to eight digits within a longer string of digits).
The only assumption here is that there are, in fact, spaces between string components. I did not assume that the eight-digit number will always be in a certain position (e.g., first, last) within the string.
Try this, take a look at Example sheet
=FILTER(TRANSPOSE(SPLIT(B2," ")),LEN(TRANSPOSE(SPLIT(B2," ")))=8)
Or this to get them all.
=JOIN(" ,",FILTER(TRANSPOSE(SPLIT(B2," ")),LEN(TRANSPOSE(SPLIT(B2," ")))=8))
Explanation
SPLIT with the dilimiter set to " " space TRANSPOSE and FILTER TRANSPOSE(SPLIT(B2," ") with the condition1 set to LEN(TRANSPOSE(SPLIT(B2," "))) is = 8
JOIN the outputed column whith " ," to gat all occurrences of number with a length of 8
Note: to get the numbers with the length of N just replace 8 in the FILTER function with a cell refrence.
Using this on a cell worked just fine for me:
(cell_with_data)=REGEXEXTRACT(A1,"[0-9]{8}$")
At Amazon Athena, I want to extract only the character string "2017-07-27" from the character string "2017-07-27 12:10:08".
SELECT SUBSTRING (event_datetime.s, 0, 10) FROM production limit 10
I tried it like this which only returns numbers 0 to 10.
At Athena, is it possible to cut character strings? If so, how can I do it?
Or, if you know how to cast "2017-07-27 12:10:08" to date type, that's fine.
Thank you.
You can use SUBSTR to substring a column value.
Here is the string function reference page.
In your case, this would lead to the following statement:
SELECT SUBSTR(event_datetime.s, 1, 10) FROM production limit 10
NOTE that the index position of the first character is 1 (not zero), the same as in standard SQL.
I am retrieving to fetch the count of rows which I gor from SQL Server using a column. I am achieving it through
xsl:value-of select='format-number(count(//Report/ABC_Data/Details_Collection/Details/Sequence_Number),"#")'
But the issue is, I need it for 6 characters & if the count is just 2 digits, say 62, I need it as 000062. Any help on this please ?
Also is there a way to add two nodes (And pad it with leading zero's : length is 20)?
I am trying as
xsl:value-of select='format-number(sum(//Report/ABC_Data/Details_Collection/Details/Initial_Amount|Final_Amount),"$#.00")'>
Your number pattern needs to look like 000000 rather than using # characters:
format-number(62, '000000')
gives 000062.
You can use a node-set in sum: try something like:
sum((//Report/ABC_Data/Details_Collection/Details/Initial_Amount, //Report/ABC_Data/Details_Collection/Details/Final_Amount))
The outer set of brackets is for the sum function; the inner set is to define a (comma separated) node set sequence. Note that each XPath term could theoretically return a sequence of more than one value!
I have values in column like "07960/WR" , "27163/WR", etc. I need to select all numbers from it. So i created sql:
select CAST (regexp_replace(object_index, '\D', '', 'g') as integer) as number from ...
Its OK, but when somebody put [number] / <- slash / ....
example: "99/27163/WR"
My query doesnt work.
How to use regexp_replace ONLY for last 5 digits in value?
I don't know PostgreSQL, but with a little help from RegexBuddy, I pieced something together that hopefully works:
select CAST (REGEXP_REPLACE(object_index, $$(?p)^.*(\d{5})\D*$$$, $$\1$$, 'g') as integer) as number from ...
The idea of this regex is to match and capture the last five digits \d{5} in the string (i. e. those that are followed only by non-digits: \D*$) and remove everything around them.