I have an SQL table that stores process data logged from an automation process. The table stores a variable name, logged value, timestamp. The table looks like this:

```
VariableName | VariableValue | Timestamp
------------------------------------------
   Tag_1     |       1       |   Time_1  
   Tag_1     |       5       |   Time_2  
   Tag_1     |       4       |   Time_5  
   Tag_1     |       8       |   Time_7   
   Tag_2     |       3       |   Time_1  
   Tag_2     |       4       |   Time_3  
   Tag_2     |       5       |   Time_6  
   Tag_2     |       7       |   Time_7  
    ...

```

Values of the variables are logged "on change", therefore they appear in the table with different timestamps. 

To be able to export the data and use them for further processing we need to sort the table and represent it in a different form, i.e.:

```
Timestamp | Tag_1 | Tag_2
--------------------------
  Time_1  |   1   |   3  
  Time_2  |   5   |   -  
  Time_3  |   -   |   4  
  Time_5  |   4   |   -  
  Time_6  |   -   |   5  
  Time_7  |   8   |   7    

```

As you can see, there are some "blind spots" in the table representing the variable values, which corresponds to the fact that simply at this time, there was no value logged for the tag, namely no change in the tag value with respect to the previously logged value. 

How do I achieve this with SQL? I most probably need a new table with the structure above. However, it needs to be created dynamically, since number of columns depends on the number of variables logged (Tag\_1, Tag\_2, etc.). 

Creating the table and querying the database is not a problem since I use VB scripts for that purpose. I do not however know how to formulate the query (a join???) to achieve that structure...