- Posts: 449
How to handle fields that contain multiple values
- FlowHeater-Team
-
Topic Author
- Offline
- Admin
-
Less
More
3 days 13 hours ago #3836
by FlowHeater-Team
Best wishes
Robert Stark
How to handle fields that contain multiple values was created by FlowHeater-Team
Hi
I am trying to take some geographic data and load it into a MS-SQL Server table.
The problem is several fields contain multiple values, and the number of them is variable from 1 to N. They are separated by commas.
I want to convert to normal relational form, so each incoming record must create a variable number of output records.
For example:
Lake A; (Town B, Town C, Town D , Town E);
The lake is shared between 4 towns. It may be divided between 1 up to an unknown maximum number of towns.
I want to end up with the following:
Lake A, Town B
Lake A, Town C
Lake A, Town D
Lake A, Town E
...
I can’t seem to figure out how to do this with Flowheater.
Are there any examples on your website?
Kind regards
Mike
Request reveived via E-Mail
I am trying to take some geographic data and load it into a MS-SQL Server table.
The problem is several fields contain multiple values, and the number of them is variable from 1 to N. They are separated by commas.
I want to convert to normal relational form, so each incoming record must create a variable number of output records.
For example:
Lake A; (Town B, Town C, Town D , Town E);
The lake is shared between 4 towns. It may be divided between 1 up to an unknown maximum number of towns.
I want to end up with the following:
Lake A, Town B
Lake A, Town C
Lake A, Town D
Lake A, Town E
...
I can’t seem to figure out how to do this with Flowheater.
Are there any examples on your website?
Kind regards
Mike
Request reveived via E-Mail
Best wishes
Robert Stark
Please Log in or Create an account to join the conversation.
- FlowHeater-Team
-
Topic Author
- Offline
- Admin
-
Less
More
- Posts: 449
3 days 13 hours ago #3837
by FlowHeater-Team
Best wishes
Robert Stark
Replied by FlowHeater-Team on topic How to handle fields that contain multiple values
Hi Mike,
You can handle this with the help of the GroupOut Heater and the little C# Script (see below) into the .NET Script Heater .
The GroupOut Heater makes just N copies of the incoming row. To figure out how many copies you need you have to count the delimiter sign in the “Towns” column with the Occur Heater .
Now you need the index of the current copied row. For this you need the AutoID Heater with enabled “GroupOut” option. With this the AutoID Heater counts from 1 to the copied row.
The .NET Script takes this row index, splits the “Towns” column by the comma sign and returns the right part.
I´ve made a brief example, see attached ZIP file.
Screenshot description
C# Script
You can handle this with the help of the GroupOut Heater and the little C# Script (see below) into the .NET Script Heater .
The GroupOut Heater makes just N copies of the incoming row. To figure out how many copies you need you have to count the delimiter sign in the “Towns” column with the Occur Heater .
Now you need the index of the current copied row. For this you need the AutoID Heater with enabled “GroupOut” option. With this the AutoID Heater counts from 1 to the copied row.
The .NET Script takes this row index, splits the “Towns” column by the comma sign and returns the right part.
I´ve made a brief example, see attached ZIP file.
Screenshot description
- Remove the start and ending brackets with 2 String Replace Heater
- Count the comma sign with the Occur Heater
- Copy the input rows
- Get the current copied row index
- Execute the script and retrieve the right Town part
- Remove white space signs
C# Script
Code:
public object DoWork()
{
// get current column index from AutoID Heater = first input value
int i = (int)InValues[0].GetInt();
// get values = second input value
string values = (string)InValues[1].GetString();
// Split into parts by comma delimiter
string [] parts = values.Split(',');
// return current part. Note: zero based index!
return parts[i];
}
Best wishes
Robert Stark
Please Log in or Create an account to join the conversation.
- Michael Orr
- Offline
- User
-
Less
More
- Posts: 2
3 days 5 hours ago #3838
by Michael Orr
Replied by Michael Orr on topic How to handle fields that contain multiple values
Thanks for the very prompt response.
Please Log in or Create an account to join the conversation.
Time to create page: 0.291 seconds