title: How to perform "Order by" on an encrypted column (deterministic encryption - SQL 2016)
body: <p>How to perform "Order by" on an encrypted column (deterministic encryption - SQL Server 2016) ?</p>
  
  <p>I am getting error when executed on SSMS 2017 (with required settings for AE)</p>
  
  <pre><code>SELECT * 
  FROM [dbo].[X] 
  ORDER BY lastName
  </code></pre>
  
  <p>The <code>lastName</code> column is defined like this:</p>
  
  <pre><code>[lastName] [varchar](60) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = [X]
  </code></pre>
  
  <p>I get an error:</p>
  
  <blockquote>
    <p>Msg 33299, Level 16, State 2, Line 9<br>
    Encryption scheme mismatch for columns/variables 'lastName'. The encryption scheme for the columns/variables is (encryption_type = 'DETERMINISTIC', encryption_algorithm_name = 'AEAD_AES_256_CBC_HMAC_SHA_256', column_encryption_key_name = 'X', column_encryption_key_database_name = 'X') and the expression near line '3' expects it to be (encryption_type = 'PLAINTEXT') (or weaker).</p>
  </blockquote>