I have a column "Amount" numeric(18,2)
that I have made encrypted by using Encrypt Column wizard of SSMS v17. The column data is now encrypted.
However, I have a view that uses something like:
create SampleView
as
Select
*, Amount * Rate as TotalAmount
From
SampleTable
Where
Amount > 0
go
The column Rate
is of type numeric(18,8)
.
I am unable to create this view. It gives data type incompatible error as one column is encrypted and the other side is plaintext. From various permutation I have tried, I see that the Where clause with > 0 is causing problem and also Amount*Rate in Select list is not working.
The error related to Amount*Rate
is (I commented Where clause)
Operand type clash: numeric(18,2) encrypted with (encryption_type = 'DETERMINISTIC', encryption_algorithm_name = 'AEAD_AES_256_CBC_HMAC_SHA_256', column_encryption_key_name = 'SampleDB_CEK', column_encryption_key_database_name = 'SampleDB') is incompatible with numeric
The error related to Where Amount>0
is (I commented Amount*Rate in Select clause)
The data types numeric(18,2) encrypted with (encryption_type = 'DETERMINISTIC', encryption_algorithm_name = 'AEAD_AES_256_CBC_HMAC_SHA_256', column_encryption_key_name = 'SampleDB_CEK', column_encryption_key_database_name = 'SampleDB') and tinyint are incompatible in the greater than operator.
I tried these, but it didn't work as well:
Where Amount > cast(0 as numeric(18,2)
Select Amount * cast(Rate as numeric(18,2)
We cannot declare variables as it is view. And this view is getting used in many stored procedures.
Any ideas appreciated.