Question: What is the best way to go about returning a result set with the distinct zone values as columns from the below basic select query?

```
SELECT weight, base_rate, zone 
FROM Rates 
WHERE modeId = 984 

```

Here is the table:

`Rates` table:

```
    id int
    modeId int
    base_rate decimal
    zone varchar
    weight decimal

```

I tried creating a pivot query to accomplish this, but so far have been unsuccessful. Any ideas? Should I just be manipulating the results in the C# code instead? The results will be put into a gridview.

This is what I would like the result set to look like

```
weight zone1 zone2 zone3 zone4
5       5.50 5.65  5.75  6.00
10      5.55 6.00  7.00  8.00
15      7.50 8.00  9.00  10.00

```

Here is my failed attempt at creating the pivot query.

```
select *
from
(
  SELECT weight, base_rate, zone FROM Rates where modeId=984 
) as d
pivot
(
  max(weight)
  for zone in (select distinct zone from d)
) piv;

```

Answer: 
Couple of ways you could do this:

1. Use an input parameter to pass all the data you need.
2. Use an input parameter to pass the ID of the record, and then use the IOrganizationService to retrieve the rest of the data.

Please see [Custom Workflow Activities (Workflow Assemblies) for Microsoft Dynamics CRM](http://msdn.microsoft.com/en-us/library/gg309745.aspx) for examples and further detail.
I am not sure what your `WorkflowHelper` does but you should not really have to use it.

```
    // Create the context
    var context = executionContext.GetExtension<IWorkflowContext>();
    //primary entityid
    var _feeRecordId = context.PrimaryEntityId

```