RK_0
(RK)
December 24, 2022, 2:53am
1
Hello Everyone.
I have a data table and 2 string variables and need to filter the data table using these two variables for different columns column1 and column2 but sometimes there will be null value in either variables.
Eg:
Variable A = abc, and variable B =“” | Variable A = abc, and variable B =xyz
Column1
Column2
abc
xyz
efg
uvw
hij
yut
klm
thj
is there is any query to filter the data table.
Yoichi
(Yoichi)
December 24, 2022, 3:00am
2
Hi,
Can you share expected output?
Regards,
RK_0
(RK)
December 24, 2022, 3:05am
3
Helo,
i have three scenarios varA filters column1 and varB filter column2
if varA= abc and varB=xyz
|Column1|Column2|
|abc|xyz|
if varA=efg and varB=“” [null]
|Column1|Column2|
|efg|xyz|
|efg|uvw|
|efg|xyz|
regarless of column2 values
vizversa for varA =“”[null]
Yoichi
(Yoichi)
December 24, 2022, 3:25am
4
Hi,
Can you try the following sample?
varA2 =if(String.IsNullOrEmpty(varA),".*","^"+System.Text.RegularExpressions.Regex.Escape(varA)+"$")
varB2 = if(String.IsNullOrEmpty(varB),".*","^"+System.Text.RegularExpressions.Regex.Escape(varB)+"$")
Then
arrDR = dt.AsEnumerable.Where(Function(r) System.Text.RegularExpressions.Regex.IsMatch(r(0).ToString,varA2) AndAlso System.Text.RegularExpressions.Regex.IsMatch(r(1).ToString,varB2)).ToArray
Sample20221224-3aL.zip (3.2 KB)
Regards,
RK_0
(RK)
December 24, 2022, 3:30am
5
Thanks for the quick response and solution.
system
(system)
Closed
December 27, 2022, 3:30am
6
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.