Question: I have 2 separate columns, 'ATFTE' and 'SATFTE'. Using these two columns, I have to perform division and store the result in a separate column (say Pyramid). I am trying to use isnull function, because in many cases, the denominator is 0 and bringing it in a subquery. It shows error - 'Invalid Column name' - ATFTE and SATFTE. How can I rectify it?

```
select isnull(ATFTE/SATFTE,0) as Pyramid
from dw_UtilizationPredictionReport
where WFMGrade in (
select WFMGrade,
    case 
        when WFMGrade IN ('P/PA','PAT','A') then sum(TotalFTE)
        else 0
    END as ATFTE,
    case
        when WFMGrade IN ('SA','M','SM','AD','D','SD','AVP','VP','SVP','EVP') 
        and WFMGrade NOT IN ('Cont') then sum(TotalFTE)
        else 0
    END as SATFTE
from dw_UtilizationPredictionReport
group by (WFMGrade)
)

```

Answer: 
Since you set your argument **newcoach** multiple times, parse\_str will only return the last one. If you want parse\_str to parse your variable as an array you need to supply it in this format with a '**[ ]**' suffix:

```
$newcoach = "newcoach[]=6&newcoach[]=11&newcoach[]=12&newcoach[]=13&newcoach[]=14";

```

**Example:**

```
<?php
  $newcoach = "newcoach[]=6&newcoach[]=11&newcoach[]h=12&newcoach[]=13&newcoach[]=14";
  $searcharray  = array();
  parse_str($newcoach, $searcharray);
  print_r($searcharray);
?>

```

**Outputs:**

```
Array ( [newcoach] => Array ( [0] => 6 [1] => 11 [2] => 12 [3] => 13 [4] => 14 ) )

```
Use this function 

```
function proper_parse_str($str) {
  # result array
  $arr = array();

  # split on outer delimiter
  $pairs = explode('&', $str);

  # loop through each pair
  foreach ($pairs as $i) {
    # split into name and value
    list($name,$value) = explode('=', $i, 2);

    # if name already exists
    if( isset($arr[$name]) ) {
      # stick multiple values into an array
      if( is_array($arr[$name]) ) {
        $arr[$name][] = $value;
     }
  else {
    $arr[$name] = array($arr[$name], $value);
  }
}
# otherwise, simply stick it in a scalar
else {
  $arr[$name] = $value;
    }
  }

  # return result array
  return $arr;
}

$parsed_array = proper_parse_str($newcoach);

```