Conditional removal of rows in importhtml data output - arrays

=ARRAYFORMULA(IFERROR(
substitute(IMPORTHTML("https://niftyinvest.com/option-chain/"&D2&"?expiry="&$B$2,"Table",1),"*","")*1,
substitute(IMPORTHTML("https://niftyinvest.com/option-chain/"&D2&"?expiry="&$B$2,"Table",1),"*","")))
where D2 = MARUTI and B2 = 30Jun2022 let's say...
Now I want to remove the row in which all columns value is zero.

Try
=query(ARRAYFORMULA(IFERROR(substitute(IMPORTHTML("https://niftyinvest.com/option-chain/"&D2&"?expiry="&$B$2,"Table",1),"*",""), substitute(IMPORTHTML("https://niftyinvest.com/option-chain/"&D2&"?expiry="&$B$2,"Table",1),"",""))),
"where "&ARRAYFORMULA(TEXTJOIN(" and ",, "Col"&SEQUENCE(11,1,1,1)&" is not null")),1)

use:
=QUERY(ARRAYFORMULA(IFERROR(
SUBSTITUTE(IMPORTHTML("https://niftyinvest.com/option-chain/"&D2&"?expiry="&$B$2,"table",1),"*",)*1,
SUBSTITUTE(IMPORTHTML("https://niftyinvest.com/option-chain/"&D2&"?expiry="&$B$2,"table",1),"*",))),
"where "&TEXTJOIN(" and ", 1, "Col"&SEQUENCE(11)&" <>0"))

Related

Oracle Select query doesnt return any results when using trim on char(2) column and database field has only spaces

Oracle Select query is not returning any results when using trim on char(2) column. The database field has only spaces. However, when the field has a space and a character, I get the correct results.
e.g.
Action_code char(2)
val = " 8"
Select * from abc where trim(Action_code) = trim(val)
Here I get the rows having " 8".
But,
val = " "
Select * from abc where trim(Action_code) = trim(val)
Here I don't get any rows from database where Action_code is " ". But I have such rows in database.
Can someone please help me how to get rows in 2nd case?
I just found that when you trim a variable or database column which has only spaces, it is treated as null by Oracle. So the following query works:
val = " "
Select * from abc where trim(Action_code) is null and trim(val) is null
Now I get the rows from database where Action_code is " ".
Why you don't try to use the nvl function ?
nvl(valueIsNull,returnOtherValue)
?

Monday count only

I just want to count the dates Monday of each number in column C filtered by column A. But it is giving an error in the formula:
=NETWORKDAYS.INTL (JANEIRO!C2, "1"; FEVEREIRO!C2, "1 ")
drive link here
paste in A2 cell and drag down:
=ARRAYFORMULA(SUM(N(REGEXMATCH(""&TRIM(SPLIT(QUERY({JANEIRO!A$2:C; FEVEREIRO!A$2:C};
"select Col1 where dayOfWeek(Col3) = 2"; 0); ",")); "^"&TO_TEXT(A2)&"$"))))
spreadsheet demo
there are no mondays. formula is:
=COUNTA(IFERROR(QUERY({JANEIRO!C2:C; FEVEREIRO!C2:C};
"where dayOfWeek(Col1) = 2"; 0)))

How to remove space when concatenating data from different rows into one column using xml?

I am trying to combine data from different rows into one column, and this is working with just one minor problem.
declare #RitID int = 16
select ...,
( select distinct
ISNULL(LTRIM(RTRIM(r2.LotNr)), LTRIM(RTRIM(r.LotNr))) + '+' as 'data()'
from tblExtraBestemming eb2
inner join tblRit r2 on eb2.RitID = r2.RitID
where eb2.BestemmingID = eb.BestemmingID
and eb2.BestemmingTypeID = eb.BestemmingTypeID
and ( (eb.CombinedChildExtraBestemmingID is null and eb2.RitID = #RitID)
or
(eb.CombinedChildExtraBestemmingID is not null and eb2.RitID in (select r4.RitID from tblRit r4 where r4.MasterRitID = #RitID) )
)
for XML PATH('')
) as LotNr
from tblExtraBestemming eb
where ...
this returns the correct data for the column LotNr, like this
GTT18196
GTT18197
GTT18198+ GTT18199
Now my only problem is the space after the + sign in the third row from the result, how can I get rid of this ?
I expect this result
GTT18196
GTT18197
GTT18198+GTT18199
PS, actually there is also a + at the end of each row, but that is removed by the client. I thought I better mentions this already.
EDIT
I checked the data, there are no spaces at the end or the beginning of the data
EDIT
Query updated as suggested by #Larnu
EDIT
if I check the data in the table, this is the result
select '/' + r.LotNr + '/' from tblRit r where r.RitID in (50798, 50799)
COLUMN1
-------
/GTT18198/
/GTT18199/
So it appears to me there are no characters before or after the data
Just remove AS 'data()' from your query (it is not required in the above case).
And if trailing + is a problem, move it to the beginning and use STUFF function to chop off the first character from the result.

Calculate Sum and Insert as Row

Using SSIS I am bringing in raw text files that contain this in the output:
I use this data later to report on. The Key columns get pivoted. However, I don't want to show all those columns individually, I only want to show the total.
To accomplish this my idea was calculate the Sum on insert using a trigger, and then insert the sum as a new row into the data.
The output would look something like:
Is what I'm trying to do possible? Is there a better way to do this dynamically on pivot? To be clear I'm not just pivoting these rows for a report, there are other ones that don't need the sum calculated.
Using derived column and Script Component
You can achieve this by following these steps:
Add a derived column (name: intValue) with the following expression:
(DT_I4)(RIGHT([Value],2) == "GB" ? SUBSTRING([Value],1,FINDSTRING( [Value], " ", 1)) : "0")
So if the value ends with GB then the number is taken else the result is 0.
After that add a script component, in the Input and Output Properties, click on the Output and set the SynchronousInput property to None
Add 2 Output Columns outKey , outValue
In the Script Editor write the following script (VB.NET)
Private SumValues As Integer = 0
Public Overrides Sub PostExecute()
MyBase.PostExecute()
Output0Buffer.AddRow()
Output0Buffer.outKey = ""
Output0Buffer.outValue = SumValues.ToString & " GB"
End Sub
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
Output0Buffer.AddRow()
Output0Buffer.outKey = Row.Key
Output0Buffer.outValue = Row.Value
SumValues += Row.intValue
End Sub
I am going to show you a way but I don't recommend adding total to the end of the detail data. If you are going to report on it show it as a total.
After source add a data transformation:
C#
Add two columns to your data flow: Size int and type string
Select Value as readonly
Here is the code:
string[] splits = Row.value.ToString().Split(' '); //Make sure single quote for char
int goodValue;
if(Int32.TryParse(splits[0], out goodValue))
{
Row.Size = goodValue;
Row.Type = "GB";
}
else
{
Row.Size = 0;
Row.Type="None";
}
Now you have the data with the proper data types to do arithmatic in your table.
If you really want the data in your format. Add a multicast and an aggregate and SUM(Size) and then merge back into your original flow.
I was able to solve my problem in another way using a trigger.
I used this code:
INSERT INTO [Table] (
[Filename]
, [Type]
, [DeviceSN]
, [Property]
, [Value]
)
SELECT ms.[Filename],
ms.[Type],
ms.[DeviceSN],
'Memory Device.Total' AS [Key],
CAST(SUM(CAST(left(ms.[Value], 2) as INT)) AS VARCHAR) + ' GB' as 'Value'
FROM [Table] ms
JOIN inserted i ON i.Row# = ms.Row#
WHERE ms.[Value] like '%GB'
GROUP BY ms.[filename],
ms.[type],
ms.[devicesn]

Which is faster "where col = ? or col = ? or col = ?" OR "where col in (?, ?, ?)" in C with informix (.ec/esql)?

Our code is written in C and DB is Informix.
We are doing some code optimization in ESQL program and found the following query:
UPDATE [TABLE] SET [PRIMARY KEY COLUMN] = [NEW KEY] WHERE COL = ? OR COL = ? ...
The number of columns in the where clause is dynamically prepared. We have an upper count check to stop preparing the where clause and do an update, then come back and start preparing the remaining. The UPPER_MARK is "30"
if ( where_parameter_count >= UPPER_MARK )
__ execute update__
__ clean_and_continue; /* start prepare again */__
We thought of replacing the WHERE .. OR with WHERE ... IN
UPDATE [TABLE] SET [PRIMARY KEY COLUMN] = [NEW KEY] WHERE COL IN (?, ? ...)
Will this be faster than "where or"?
Either syntax resolves down to the same thing as far as the Query Optimizer is concerned. It won't make any difference.
The only advantage to the in-list approach is that adding additional predicates won't change the logic, i.e.
x IN (a, b) AND y = z
and
x = a OR x = b AND y = z
are NOT the same thing.

Resources