Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL Generate Missing Records in SELECT
    primarykey
    data
    text
    <p>Using MS SQL Server 8.0.760 (2000)</p> <p>I have a Table like this:</p> <pre><code>Table A Day | Hour | Value 2012-10-01| 12 | 780 2012-10-01| 14 | 678 2012-11-02| 08 | 123 2012-11-02| 09 | 473 </code></pre> <p>Expected Result should be:</p> <pre><code>Day | Hour | Value 2012-10-01| 00 | 0 2012-10-01| 01 | 0 2012-10-01| 02 | 0 2012-10-01| .. | .. 2012-10-01| 12 | 780 2012-10-01| 13 | 0 2012-10-01| 14 | 678 2012-10-01| .. | .. 2012-10-01| 22 | 0 2012-10-01| 23 | 0 2012-10-01| 24 | 0 2012-11-02| 00 | 0 2012-11-02| 01 | 0 2012-11-02| 02 | 0 2012-11-02| .. | .. 2012-11-02| 08 | 123 2012-11-02| 09 | 473 2012-11-02| .. | .. 2012-11-02| 22 | 0 2012-11-02| 23 | 0 2012-11-02| 24 | 0 </code></pre> <p>So the missing hours are generated with Zero Values..</p> <p>Any Idea?</p> <p><strong>EDIT 1</strong></p> <p>Tried this:</p> <pre><code>DECLARE @tmpHours TABLE ( tmpHour varchar(2) ) INSERT INTO @tmpHours VALUES ('00') INSERT INTO @tmpHours VALUES ('01') ... INSERT INTO @tmpHours VALUES ('23') INSERT INTO @tmpHours VALUES ('24') SELECT * FROM [A] FULL JOIN @tmpHours tmp ON tmp.[tmpHour] = [A].[Hour] ORDER BY [Day], [Hour], [tmpHour] </code></pre> <p>But this generates this:</p> <pre><code>Day Hour Value tmpHour NULL NULL NULL 00 NULL NULL NULL 01 NULL NULL NULL 02 NULL NULL NULL 03 NULL NULL NULL 04 NULL NULL NULL 05 NULL NULL NULL 06 NULL NULL NULL 07 NULL NULL NULL 10 NULL NULL NULL 11 NULL NULL NULL 13 NULL NULL NULL 15 NULL NULL NULL 16 NULL NULL NULL 17 NULL NULL NULL 18 NULL NULL NULL 19 NULL NULL NULL 20 NULL NULL NULL 21 NULL NULL NULL 22 NULL NULL NULL 23 NULL NULL NULL 24 2012-10-01 00:00:00.000 12 780 12 2012-10-01 00:00:00.000 14 678 14 2012-11-02 00:00:00.000 08 123 08 2012-11-02 00:00:00.000 09 473 09 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload