title: How to encrypt and decrypt integer data type column in SQL Server using symmetric key
body: <p>I can encrypt and decrypt varchar, nvarchar,char columns using symmetric key but cannot do the same on int,datetime,float,bigint data types columns</p>
  
  <p>Sample table: Mytable</p>
  
  <pre><code>| Id  Code  percentage  name    activity   |  
  +------------------------------------------+
  | 1   ad     43.43    James    Running     |  
  | 3   Pr     70.43    Sam      Cooking     |  
  | 5   nt     90.34    Lisa     Walking     |  
  | 4   ash    0.00     James    Stealing    |  
  | 2   han    0.00     James    Lacking     |  
  | 8   ant    73       Sam      Cooking     |
  </code></pre>
  
  <p>I want to encrypt and decrypt ID column and Percentage which are of integer and float data types respectively.    </p>
  
  <p>I am using this code to encrypt:</p>
  
  <pre><code>OPEN SYMMETRIC KEY SymKey DECRYPTION BY CERTIFICATE data  
  
  ALTER TABLE Mytable 
  SET ADD idencry VARBINARY(128) NULL  
  
  
  UPDATE Mytable 
  SET idencry = ENCRYPTBYKEY(KEY_GUID('datamSymKey'), CONVERT(varbinary, ID))
  </code></pre>
  
  <p>To decrypt I am using this code:    </p>
  
  <pre><code>SELECT 
      id,
      CONVERT(NVARCHAR(60), DECRYPTBYKEY(idencry )), * 
  FROM 
      Mytable
  </code></pre>
  
  <p>But its not returning the correct result... same goes with float and datetime date type</p>