I have multiple columns in which i want to check account code column contains BG15 IF exist then update status column with account number from AccNo column else no action required in status column without looping as there are more than 50000 data.
For e.g.
If AccCode column contains BG15 code before 1st comma then it should return account number before 1st comma from accnum column and update to status column
For example input data:
you need to get data as a data table lets say dt_acc_codes
loop through each row
below pseudo code is for one iteration
start For Each
split the values in each cell at “,”
lets say Split_Code = {“ETG88”,“TBG15”} Split_Code is String[ ] Split_Acc = {“AJ125648”,“AC788555”} Split_Acc is String[ ]
if Split_Code current_element contains “BG15”
get index_code = Array.IndexOf(Split_Code, current_element) Status_Acc = Split_Acc(index_code)
update Status with Status_Acc
End For Each
you need to handle scenarios if Split_Code and Split_Acc are having only one element
(From row In dt_sampleData.AsEnumerable()
Let lstItem = row("AccNum").ToString.Split({","c}, StringSplitOptions.RemoveEmptyEntries).Last()
Let status = If(row("AccCode").ToString.Trim.Split({","c},StringSplitOptions.RemoveEmptyEntries).Any(Function(a) a.Contains("BG15")),lstItem,"")
Let ra = New Object(){row("AccCode"),row("AccNum"),status}
Select dt_result.Rows.Add(ra)).CopyToDataTable()
I have more than 50 columns before this columns how to get that columns also with this query.
I want those column as well in output dt along with updated status column.
Its impossible for us to provide you with a solution unless you provide little more detail, like which indexes the columns you have shared with us are present at, or even if you had a sample data sheet that you could share with us, that would be really helpful.
Before given 3 columns i have 50 columns with data with column status blank…so just want to fill status column if any required condition match. I want that 50 columns along with updated Status as well.
So you mean to say that there are 50 columns, after which the three columns you have shown us are present?
If so, then update the second last line like so
this →
Let ra = row.ItemArray.Take(50).Concat{row("AccCode"),row("AccNum"),status}
If there are 50 columns, with the 50th column being the status column, then try this →
Let ra = row.ItemArray.Take(49).Append(status).ToArray()