Question: I'm attempting to change the innerHTML of a div from the ready function of an iframe's src. Code below. The innerHtml will not change, but the color works fine. Ideas on why this is happening and/or how to fix it?

Page

```
<html><head></head><body>
<script type="text/javascript" src="Javascript/Import_Subprocess_Content/RAC_Connolly.js"></script>
<div id="importcontent" runat="server">
</div>
<iframe id="frametest" src="./AJAX/Import_Subprocess_Content/RAC_Connolly_ImportSession.aspx">

</iframe>
<div id="popup">FIRST TEXT</div>

</body>

```

Iframe src

```
<script type="text/javascript" src="../../Utilities/Javascript/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="../../Javascript/Import_Subprocess_Content/RAC_Connolly.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        uploadComplete();
    });
</script>
end it!

```

js

```
function uploadComplete() {
    window.parent.document.getElementById("popup").innerHtml = "lala";

}

```

Testing in IE7 exclusively.

Answer: 
What database are you using? The capabilities of the database are important. Second, this suggests a data structure issue. Things that need to be sorted would normally be separate entities . . . that is, separate rows in a table. The rest of this post answers the question.

If the database supports pivot/unpivot you can do the following:

(1) Unpivot the data to get in the format , , 
(2) Use row\_number() to assign a new column, based on the ordering of the values.
(3) Use the row\_number() to create a varchar new column name.
(4) Pivot the data again using the new column.

You can do something similar if this functionality is not available.

First, change the data to rows:

```
(select id, 'col1', col1 as val from t) union all
(select id, 'col2', col2 from t) union all
. . .

```

Call this byrow. The following query appends a row number:

```
select br.*, row_number() over (partition by id order by val) as seqnum
from byrow br

```

Put this into a subquery to unpivot. The final solution looks like:

```
with byrow as (<the big union all query>)
select id,
       max(case when seqnum = 1 then val end) as col1,
       max(case when seqnum = 2 then val end) as col2,
       ...
from (select br.*, row_number() over (partition by id order by val) as seqnum
      from byrow br
     ) br
group by id

```
Here is a good example using PIVOT, you should be able to adapt this to meet your needs

<http://blogs.msdn.com/b/spike/archive/2009/03/03/pivot-tables-in-sql-server-a-simple-sample.aspx>