Question: I have a view in my SQL Server database named `PictureCount`. I am getting data according the following query-

```
with result as
(SELECT CAST(Createddate AS DATE) AS StartDate, COUNT(ServicePictureID) AS TotalPicture 
 FROM PictureCount 
 WHERE ProjectID='11' AND 
 CAST(CreatedDate As DATE) BETWEEN '2014-10-31' AND '2014-12-05' 
 GROUP BY CAST(Createddate AS DATE)
)
SELECT 
   (CAST(DATEPART(YYYY, CAST(StartDate AS DATE)) as varchar) + '-' + CAST(DATEPART(MONTH ,CAST(StartDate AS DATE)) AS varchar)) AS StartDate, 
   TotalPicture 
FROM result

```

Data is appearing in the following format-

![enter image description here](https://i.stack.imgur.com/b18T0.jpg)

But I want data with group by `StartDate`. I am not able to apply `GROUP BY` clause. Please tell me if anyone knows about it. 

Thanks in advance.

Answer: 
An alternative approach that would not depend on any specific implementation like `jqGrid` would be to keep an array with the column names like:

```
var columnNames = [];

$('table').find('th').each (function () {
   columnNames.push($(this).text().trim());
});

```

Then you can get an index of a column with a O(1) operation:

```
var index = columnNames.indexOf("Inv No");

```

And you can use that index in your existing expression:

```
$('textbox').val($(e.target).closest("tr").find('td:eq(' + index + ')').text());

```

This would give you the flexibility to switch to another table/grid plugin without changing the code!

Here is an example applied to HTML rendered by jqGrid:

<http://jsfiddle.net/fukt548f/1/>
```
this may help you
$('textbox').val($(e.target).closest("tr").children().eq(4).text());

```