This question already has an answer here:
Virtually blank column in array?
(1 answer)
Closed 5 months ago.
I have this file with an input table in Google Sheets.
Keys
Tags
V1
V2
kEp
tag1
30
12
PgZ
tag2
8
2
pac
tag3
15
21
This is what i did; I added REGEXREPLACE(QUERY({A1:D},"Select Col1"),".+"," ") to get the empty column I
=ArrayFormula({
QUERY({A1:D}," Select Col1,Col2,Col3 ",1),
REGEXREPLACE(QUERY({A1:D},"Select Col1"),".+"," "),
QUERY({A1:D}," Select Col1,Col2,Col4 ",1)})
The ask
Is there is a simple way with the same range refrence this case A1:D to add an empty column to the array {} like this &""& ?
If 'empty' doesn't really have to be that empty, this is pretty simple...
=QUERY({A1:D4,A1:B4},"select Col1,Col2,Col3,' ',Col5,Col6,Col4 label ' '''")
You can try-
={QUERY({A1:D}," Select Col1,Col2,Col3 where Col1 is not null",1),
FLATTEN(SPLIT((REPT(" |",COUNTA(A:A))),"|")),
QUERY({A1:D}," Select Col1,Col2,Col4 where Col1 is not null",1)}
And simplified formula-
={QUERY(A:D,"select A,B,C where A is not null",1),
FLATTEN(SPLIT((REPT(" |",COUNTA(A:A))),"|")),
QUERY(A:D,"Select A,B,D where A is not null",1)}
Get different cuts of the range through OFFSET and join them along with empty arrays crafted with MAKEARRAY:
=LAMBDA(rg,where,how_many,
{
OFFSET(rg,0,0,,where),
MAKEARRAY(ROWS(rg),how_many,LAMBDA(r,c,)),
OFFSET(rg,0,where,,COLUMNS(rg)-where)
}
)(A1:INDEX(D:D,COUNTA(D:D)),1,2)
This question already has answers here:
how to extract address number from string in T-SQL [duplicate]
(4 answers)
Closed 4 years ago.
I have number in string and I need length of number only in string, how can I do that?
120 westminister way Road, London (NW10 5NQ)
5 westminister way Road, London (NW10 5NQ)
select
LEN( PATINDEX('%[0-9]%', [address])) doorNoLength
output expected
i) 3
2) 1
Why not just do ?
SELECT LEN(LEFT(address, PATINDEX('%[A-Z]%', address)-1)) AS doorNoLength
This question already has answers here:
Get the number of digits after the decimal point of a float (with or without decimal part)
(6 answers)
Closed 4 years ago.
The column CostPrice of table t1 is money type.
The data in column CostPrice likes this:
141.1938
0.00
147.1041
119.592
1.23
I use this sql to get the decimal digits:
select distinct len(CostPrice-floor(CostPrice))-2 from t1;
But the result is only 2,this is not right,in fact,the result should be 2,3,4.
So how to fix the sql?
Added:
StackOverflow does not allow me to flag the flagging but asked me to edit the question instead, so:
This Question is not a duplicate to this one. The existing question is on the "float" datatype and this one is on "money", Converting "money" to "varchar" like in the "existing anser" will always return the same number of decimal places, so it does not answer this question.
You could (independantly from regional settings):
multiply the value by 10,000
convert the result to integer
convert the integer to a string
add 4 leading zeroes to the left (just in case...)
take the 4 characters from the right (the former decimal places)
replace each zero by a blank character
remove the trailing blanks using rtrim
return the length of the remaining string
To put this in an expression, it would be:
LEN(RTRIM(REPLACE(RIGHT('0000' + CONVERT(varchar(20), CONVERT(int, CostPrice*10000)), 4), '0', ' ')))
Try this
DECLARE
#money money = 141.1938
SELECT
#money
,SUBSTRING(CONVERT(varchar(20),#money,2), CHARINDEX('.', CONVERT(varchar(20),#money,2)) + 1, LEN(CONVERT(varchar(20),#money,2))) as RESULT
This question already has answers here:
LISTAGG function: "result of string concatenation is too long"
(14 answers)
Closed 6 years ago.
Is there some function that makes the same behavior of SYS.STRAGG in oracle but instead of returning VARCHAR (and being limited to the VARCHAR size), it returns a CLOB , and thus allows (virtually) infinite number of concatenated strings ?
for example , I have a query select x from y where z that returns 2.5M records and I want to return all these records concatenated together 1 shot
XML functions can be used for such aggregation but for 2.5M records it will be very slow.
Example:
SELECT
rtrim(
dbms_xmlgen.convert(
extract(
xmlroot(
xmlelement(
"x",
xmlagg(sys_xmlgen(object_name || ', '))
),
version '1.0'),
'/x/ROW/text()').getclobval(),
1),
', ') aggregated_data
FROM
all_objects
You might consider to use LISTAGG for pre-aggregation of small row groups into VARCHARs smaller than 4000/32767 bytes and then use the XML aggregation for the final result.
This question already has answers here:
Convert numbers to dates [duplicate]
(2 answers)
Closed 9 years ago.
I have input data with date and time stamps as "140128142257" which is the equivalent of "14/01/28 14:22:57" or "%Y/%m/%d %H:%M:%S".
I cannot get R to read this in so I can convert it to a usable date and timestamp. Any helpful advice would be appreciated.
Here is what I have tried:
datetime <- as.POSIXct(strptime(date[,2],format="%Y%m%d%H%M%S")
However this just gives NA * length of array.
The uppercase %Y is used for four-digit years. You have to use %y for two-digit years.
strptime("140128142257", format = "%y%m%d%H%M%S")
# [1] "2014-01-28 14:22:57"