Convert a Table Column into a Concatenated String


#1

What is the use case

In a database query, we may need to pass a list of IDs into the in (‘xxx’,‘xxx’,‘xxx’) expression.
And the list is usually sourced from a data table, either from an Excel file or extracted from a website.
So, it’ll really be helpful if we can conveniently convert a table column into this format: ‘xxx’,‘xxx’,‘xxx’

How do you see a solution for the use case?

I create a re-usable workflow which can easily apply to such cases.

Input:

  1. datatable - the source datatable
  2. i - the index of the table column, starting from 0.
  3. startwith - fill in this if you want to add something like a single quote before each ID
  4. endwith - fill in this if you want to add something like a single quote after each ID
  5. separator - the separator between each ID, such as a comma.

Output is the concatenated string.

Scope: ______________

  • Reusable Component

ColumnToString.xaml (11.4 KB)


#2

You might include this idea for the scope of Custom Activities also.

Sounds like you just want the equivalent of the below lambda expression:

String.Join(",",dt1.AsEnumerable.Select(Function(row) "'"+row("column").ToString.Trim+"'" ).ToArray )

But in a more user-friendly sense like Custom activity.