title: Passing parameter into “Row_Number”
body: <p>I am getting the following <strong><code>syntax error</code></strong> with the following query when i try to parameterize column name.   <strong><code>Incorrect syntax near '@SortBy'.</code></strong></p>
  
  <p>I was able to make it work using a dynamic SQL but the problem is <strong><code>Entity Framework</code></strong>  won't create complex types for <strong><code>SPs with exec</code></strong>. </p>
  
  <p>Is there a way/work around  to make this query work other than dynamic SQL. </p>
  
  <pre><code>DECLARE
          @MLSIdList varchar(max),
      @SortBy varchar(max),
      @LowRow int,
      @HighRow int
  
  SET @MLSIdList = '12-632393,12-73464,12-39834,12-78237'
  SET @SortBy = 'ORDER BY a.mlsnum, a.yb, a.RatePlugMID  '
  SET @LowRow = 11
  SET @HighRow = 23
  
  
  SELECT a.mlsId , a.ADDRESS, a.APN , a.RatePlugMID,a.hod , a.yb , a.UNUM ,
         a.CHANGETYPE , a.CITY , a.County,  ROW_NUMBER() OVER ( @SortBy ) AS RowNumber,
  FROM mls_unified_svo_tbl a (nolock) 
  WHERE a.MLSNUM IN ( @MLSIdList ) 
  </code></pre>