title: Incorrect syntax near the keyword SELECT
body: <p>I try to group by my purchases by <strong>hour</strong> .In this case I lave number hours that I have not any purchase in it. I want check select query and if once of hours (<strong>0 1 2 .... 22 23</strong>  ) not exist into select query : add a record with default value into <code>@Table</code> .I  get this error : </p>
  
  <blockquote>
    <p>Incorrect syntax near the keyword SELECT</p>
  </blockquote>
  
  <p>How can i fix this?</p>
  
  <pre><code>    DECLARE @Table AS TABLE (Price DECIMAL, NumberOfPhurchase INT, Hour INT);
      DECLARE @i AS INT = 0;
      DECLARE @j AS INT = 0;
  
      INSERT INTO @Table (Price,NumberOfPhurchase,Hour)
      VALUES
        (
          SELECT SUM(p.Price)    ,
             COUNT(p.Price)  ,
             DATEPART(HOUR, p.IssueDate)
      FROM   dbo.Payments    AS p
      WHERE  p.[state] = 6
             AND p.Transactionsuccess = 1
             AND (p.ReserveType = @ReserveType OR @ReserveType = 0)
             AND p.IssueDate &gt;= @StartDate
             AND p.IssueDate &lt;= @EndDate
      GROUP BY
             DATEPART(HOUR, p.IssueDate)
  
        )
  
  
      WHILE @i &lt;= 23
      BEGIN
          SET @j =  
          SELECT COUNT(*) FROM @Table 
          WHERE  @Table.Hour = @i;
          IF @j = 0
          BEGIN
              INSERT INTO @Table
                (
                  Price,
                  NumberOfPhurchase,
                  Hour
                )
              VALUES
                (
                  0,
                  0,
                  @j
                )
          END
          SET @i=@i+1;
      END
      SELECT
          @Table.Price,
          @Table.NumberOfPhurchase,
          @Table.Hour
      FROM
          @Table
  </code></pre>