title: group by clause issue
body: <p>I have written a query in access and now I am trying to write the same in SQL Server I am getting following error:</p>
  
  <blockquote>
    <p>Msg 164, Level 15, State 1, Procedure OQRY_STEP_1_1, Line 15
    Each GROUP BY expression must contain at least one column that is not an outer reference.</p>
  </blockquote>
  
  <p>My SQL Query is as follows:</p>
  
  <pre><code>SELECT
      ns11.SYS_ID,
      ns11.SUB_NET_ID,
      ns11.TEMP_ID,
      ns11.EQ_ID,
      ns11.NODE_NAME,
      ns11.EQ_NAME,
      ns11.VAR_NAME,
      ns11.VAR_SET,
      ns11.VAR_SUBSET,
      ns11.EQ_TYPE,
      ns11.RHS_RELN,
      ns11.RHS_OBJECT,
      ns11.EQ_TP_OFFSET,
      ns11.RHS_TP_OFFSET,
      ns11.RETAIN,
      nmte.RHS_VAR_SET,
      nmte.RHS_VAR_SUBSET,
      nmte.RHS_VAR_NAME,
      0 AS RHS_VAR_TYPE,
      CASE
          WHEN [asp].[VALUE] = NULL THEN 0
          ELSE [asp].[VALUE]
      END RHS_VALUE
  INTO ##OT_STEP_1_1
  FROM (##NT_STEP_1_1 ns11
      INNER JOIN ##NT_MASTER_TEMP_EQUATION nmte
          ON (ns11.SYS_ID = nmte.SYS_ID)
              (ns11.SUB_NET_ID = nmte.SUB_NET_ID)
          AND (ns11.TEMP_ID = nmte.TEMP_ID)
          AND (ns11.EQ_ID = nmte.EQ_ID)
          AND (ns11.NODE_NAME = nmte.NODE_NAME)
          AND (nmte.SYS_ID = ns11.SYS_ID)
          AND (nmte.SUB_NET_ID = ns11.SUB_NET_ID))
      LEFT JOIN AMST_SIM_PAR asp ON 
          (nmte.SYS_ID = asp.SYS_ID)
          AND (nmte.SUB_NET_ID = ns11.SUB_NET_ID)
          AND (nmte.RHS_VAR_NAME = asp.VAR_NAME)
  GROUP BY
      ns11.SYS_ID,
      ns11.SUB_NET_ID,
      ns11.TEMP_ID,
      ns11.EQ_ID,
      ns11.NODE_NAME,
      ns11.EQ_NAME,
      ns11.VAR_NAME,
      ns11.VAR_SET,
      ns11.VAR_SUBSET,
      ns11.EQ_TYPE,
      ns11.RHS_RELN,
      ns11.RHS_OBJECT,
      ns11.EQ_TP_OFFSET,
      ns11.RHS_TP_OFFSET,
      ns11.RETAIN,
      nmte.RHS_VAR_SET,
      nmte.RHS_VAR_SUBSET,
      nmte.RHS_VAR_NAME,
      0,
      CASE
          WHEN [asp].[VALUE] = NULL THEN 0
          ELSE [asp].[VALUE]
      END
  ORDER BY
      CASE
          WHEN [asp].[VALUE] = NULL THEN 0
          ELSE [asp].[VALUE]
      END;
  </code></pre>
  
  <p>I am not sure why it is not taking 0 in the group by clause?</p>