Question: I have the following table:

<http://i42.tinypic.com/sovfab.png>

I need to insert all fields into a new table in mysql when I clicked on "plus" button. In adition I need to show this modal:

<http://i39.tinypic.com/mrd63k.png>

In resume, I need to insert data and show modal on the same click.

I'm using MVC with codeigniter.

I can insert data and show the modal if I did that independently.

* To insert data:

I'm using the controller and all parameters were insert using the URL.
**Example:** *Localhost/Index.php/Controller?Parameter1&Parameter2&Parameter3*
* To show modal:

I'm calling in the view with javascript function with `onclick="test()"` and the function has

> 
> `function test(){ $('#myModal').modal('show'); }`
> 
> 
> 

. Or more simply I can use 

> 
> `<a href="#myModal" role="button" class="btn" data-toggle="modal">Launch demo modal</a>`
> 
> 
>

Answer: 
Your case is certainly a candidate for using PIVOT table syntax. The below is a simple query which does pivot. 

```
SELECT Department_number
,[January]
,[February]
,[March]
FROM (
SELECT Department_number, Amount, datename(date_created) AS month_created from <Your_Table>
) AS SOURCETABLE
PIVOT(SUM([Amount]) FOR month_created IN ([January],[February],[March])) AS PIVOTTABLE

```

This query assumes you have date\_created column containing values Jan,Feb,March in your table. You may add more months if you need.

More on the subject - <http://technet.microsoft.com/en-us/library/ms177410(v=sql.105).aspx>
If you want to display this in SSRS report then go for Row and Column grouping and aggregate the amount otherwise you can use Pivot Table with TSQL : [How to pivot table with T-SQL?](https://stackoverflow.com/questions/9830960/how-to-pivot-table-with-t-sql)