How to perform "Order by" on an encrypted column (deterministic encryption - SQL Server 2016) ?
I am getting error when executed on SSMS 2017 (with required settings for AE)
SELECT *
FROM [dbo].[X]
ORDER BY lastName
The lastName
column is defined like this:
[lastName] [varchar](60) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = [X]
I get an error:
Msg 33299, Level 16, State 2, Line 9
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).