Convert rows to constant columns in SQL Server?
<p>I have the following query with its result:</p>

<pre><code>SELECT * FROM dbo.DeviceView AS dv
WHERE DeviceId = 5
</code></pre>

<p>Result:</p>

<pre><code>Id      Name                        AttachId        ColorId     Date
---     -------                     ----------      -------     -------
5       Apple iPhone 5s A1533       NULL            1           2013-09-10 00:00:00.000
5       Apple iPhone 5s A1533       NULL            8           2013-09-10 00:00:00.000
5       Apple iPhone 5s A1533       NULL            19          2013-09-10 00:00:00.000
</code></pre>

<p>ColorId is within diffrent values and it can be more or less than 3 values<br>
I want to convert ColorId to 3 columns, such as first value in <code>ColorId1</code> and second value in <code>ColorId2</code> and third value in <code>ColorId3</code>.<br>
eg: </p>

<pre><code>Id      Name                        AttachId    ColorId1    ColorId2    ColorId3    Date
---     -------                     ----------  ----------  ----------  ----------  -------
5       Apple iPhone 5s A1533       NULL        1           8           19          2013-09-10 00:00:00.000
</code></pre>

<p>How can I convert it to the following?<br></p>

<p><strong>Edit</strong>:<br>
All other fields except <code>ColorId</code> are the same.</p>