I have a script in trigger to insert the audit table if any update happens on T\_Referral table and i am using a Decrypt function to Decrypt the data in one of the column. My code in trigger is :

```
DECLARE @Sql_Insert nvarchar(max)
SET @Sql_Insert = ''
SET @Sql_Insert='INSERT INTO [Logg].AuditLogData(TableName, ColumnName, OldValue, OldValue_Decode, NewValue, NewValue_Decode, AuditSubCategoryID,[GuID])
select TableName, ColumnName, OldValue_Decode, case when ColumnName = ''BookingUserReferenceValue'' then utl.sfDecrypt(NewValue,0) Else NewValue end, NewValue_Decode, AuditSubCategoryID,[GuID] from #AuditLogData
where ISNULL(OldValue,'') != ISNULL([NewValue],'')'

exec utl.uspOpenOrCloseEncryptionKey 'open'
exec(@Sql_Insert )
exec utl.uspOpenOrCloseEncryptionKey 'close'

```

---

My update script is 

```
Update RTS.T_Referral   
set BookingUserReferenceValue =  cast ('John Wayne' as varbinary(256))
where ReferralId = 20

```

I am Updating the record to `John Wayne` as varbinary in `T_Referral` table(record looks like `0x4A6F686E205761796E65`) and when update trigger is called it would load that record as John Wayne in Audit table. When the record is inserted in BookingUserReferenceValue it will be encrypted. The datatype of column BookingUserReferenceValue is Varbinary(256). when i try to update the record in that column i get error :

> 
> An expression of non-boolean type specified in a context where a
>  condition is expected, near ')'.
> 
> 
> 

Any Idea whats wrong?
Thanks