How to separate comma separated and where condition in LINQ - sql-server

I have a giftcardamounts in database table.
Column contains dollar and comma separated values.
There are 40 rows.
Ex:
row 1: giftcardamounts : ($10,$20,$30,$40,$50)
row 2: giftcardamounts : ($100,$200,$30,$40,$50)
row 3: giftcardamounts : ($10,$20,$300,$400,$500)
...etc
From frontend there is an input is giftcardselectedamount
Ex: giftcardselectedamount=500
Based on this input amount in need to write LINQ query on dollar and comma separated list of Values.
Please help me how to write this.

Like commenters have noted, you should show some effort in reaching to an answer. Also your question isn't quite clear. Are you asking to return the row with a matching amount? If so you can try the following approach, which returns the first row that contains the dollar amount specified:
void Main()
{
var data = new[] {
"$10,$20,$30,$40,$50",
"$100,$200,$30,$40,$50",
"$10,$20,$300,$400,$500"};
var giftcardSelectedAmount = 500M;
var matchingRow = data.FirstOrDefault(x => x
.Split(',')
.Any(v => decimal.Parse(v, NumberStyles.Currency) == giftcardSelectedAmount));
Console.WriteLine(matchingRow);
}
I can easily modify this answer to return all matching rows, a count of occurrences, or a count of rows with occurrences. Let me know if you need any of these modifications and I can modify my answer to add these.

Related

What is wrong with this expressions? =CountRows(ReportItems!Textbox58.Value = "Intervene"). I want to count each row which says Intervene

What is wrong with this expression? =CountRows(ReportItems!Textbox58.Value = "Intervene")
I want to count each row which says Intervene.
As Larnu has commented, you cannot use CountRows against the ReportItems collection.
Probably what you need to do is
Look at the expression in Textbox58 and see where it gets it's data from. In this exmaple let's say it comes from Fields!myFieldName.Value.
Now we need to count the rows where Fields!myFieldName.Value = "Intervene" but rather than using count, we can convert these matches to return 1 or 0 where the field is not "Intervene"
So the expression would look something like this
=SUM(IIF(Fields!myFieldName.Value = "Intervene", 1, 0))
This will sum the rows withing the current scope, so if this is contained in a row group for example, then it will only sum those rows in that row group.
If you need to count based on a a different scope (e.g. the entire dataset) then you can specify that in the SUM() function like this
=SUM(IIF(Fields!myFieldName.Value = "Intervene", 1, 0), "DataSet1")
Here we are summing across the entire dataset where the dataset name is DataSet1
Update based on OP comment
As your expression is
=SUM(IIF(Fields!Actual_Duration.Value >= 10, "Intervene", "No Intervention Needed"))
What we actually need to count is instances where Actual_Duration is >= 10.
So the final expression should be
=SUM(IIF(Fields!Actual_Duration.Value >= 10, 1, 0))

how to get x no. columns data from same row to single column with comma seperated

I want all data from column "A" to single-cell "d5" with comma-separated.
Example:
I have the following data in a sheet.
A1=john
A2=berry
A3=spartan
A4=sparrow
result i need is "john,berry,spartan,sparrow" in cell "d5".
Also, it would be great if I can set the desired no of rows instead of all.
like if required one than = "john" and
if required three than = "john,berry,spartan"
try like this:
=TEXTJOIN(","; 1; A:A)
for 3 use:
=TEXTJOIN(","; 1; A1:A3)

Anychart tables: How to include thousand separators?

How can I put the text "100.000" in a table in Anychart? When I try to get the string "100.000" in, it is modified to "100".
For a working example see https://jsfiddle.net/Republiq/xcemvm9L/
table = anychart.standalones.table(2,2);
table.getCell(0,0).content("100.000");
table.container("container").draw();
If you want to use such number formatting for the whole table you can define numberLocale in the beginning. If the actual number is 100 and '.' - is a decimal separator and you want to show 3 zeros as decimals, put the following lines before creating the table:
anychart.format.locales.default.numberLocale.decimalsCount = 3;
anychart.format.locales.default.numberLocale.zeroFillDecimals = true;
And then put in the number as:
table.getCell(0,0).content(100);
If '.' - is a group separator and the actual number is 100000, put the following line:
anychart.format.locales.default.numberLocale.groupsSeparator = '.';
And then put in the number as:
table.getCell(0,0).content(100000);
If you want to use special format only for a single cell, we recommend you to use number formatter, which helps to configure all these options only for a single number. For example, it may looks like:
table = anychart.standalones.table(5,5);
table.getCell(0,0).content(anychart.format.number(100000, 3, ".", ","));
table.container("container").draw();
Also, you may learn more about this useful method and find examples in this article

MATLAB Extract all rows between two variables with a threshold

I have a cell array called BodyData in MATLAB that has around 139 columns and 3500 odd rows of skeletal tracking data.
I need to extract all rows between two string values (these are timestamps when an event happened) that I have
e.g.
BodyData{}=
Column 1 2 3
'10:15:15.332' 'BASE05' ...
...
'10:17:33:230' 'BASE05' ...
The two timestamps should match a value in the array but might also be within a few ms of those in the array e.g.
TimeStamp1 = '10:15:15.560'
TimeStamp2 = '10:17:33.233'
I have several questions!
How can I return an array for all the data between the two string values plus or minus a small threshold of say .100ms?
Also can I also add another condition to say that all str values in column2 must also be the same, otherwise ignore? For example, only return the timestamps between A and B only if 'BASE02'
Many thanks,
The best approach to the first part of your problem is probably to change from strings to numeric date values. In Matlab this can be done quite painlessly with datenum.
For the second part you can just use logical indexing... this is were you put a condition (i.e. that second columns is BASE02) within the indexing expression.
A self-contained example:
% some example data:
BodyData = {'10:15:15.332', 'BASE05', 'foo';...
'10:15:16.332', 'BASE02', 'bar';...
'10:15:17.332', 'BASE05', 'foo';...
'10:15:18.332', 'BASE02', 'foo';...
'10:15:19.332', 'BASE05', 'bar'};
% create column vector of numeric times, and define start/end times
dateValues = datenum(BodyData(:, 1), 'HH:MM:SS.FFF');
startTime = datenum('10:15:16.100', 'HH:MM:SS.FFF');
endTime = datenum('10:15:18.500', 'HH:MM:SS.FFF');
% select data in range, and where second column is 'BASE02'
BodyData(dateValues > startTime & dateValues < endTime & strcmp(BodyData(:, 2), 'BASE02'), :)
Returns:
ans =
'10:15:16.332' 'BASE02' 'bar'
'10:15:18.332' 'BASE02' 'foo'
References: datenum manual page, matlab help page on logical indexing.

Count rows with value Yes in column Winforms

I have a Winform with 3 column access table. I find total number of rows in access table as below
lblnoofrow.Text = "Total no of rows :- " + tbl.Rows.Count.ToString()
Now I have to find number of rows with Yes in column named Completed. Please help.
Thanks
If you have already retrieved that table and you have it at your disposal in your code, you could count the rows with the YES string inside a column with this code
lblnoofrow.Text = "Total no of rows :- " +
tbl.AsEnumerable().Count(x => x.Field<string>("Completed") == "Yes");
Here I assume that your column is of type string, but if it is a YesNo field then change the <string> to <bool> and compare against true/false
lblnoofrow.Text = "Total no of rows :- " +
tbl.AsEnumerable().Count(x => x.Field<bool>("Completed") == true);
(well the compare against true is not really needed but in this case I think it makes things more readable)

Resources