title: SQL Server error code 245 (Conversion failed while converting varchar to int)
body: <p>My problem is I cannot concat a  <code>varchar(4000)</code> type variable to query in a stored procedure. </p>
  
  <p>I tried many things to get it worked, diffrent combinations with quotes but no chance. </p>
  
  <p>Here is my procedure : </p>
  
  <pre><code>@sirketkodu varchar(30) , 
  @degerler varchar(4000),
  @ORA_KULLANICI_KODU varchar(30) ,
  @ORA_KULLANICI_TIPI varchar(30) ,
  @ORA_KULLANICI_BIRIMI varchar(30) ,
  @ORA_KULLANICI_ROLU varchar(50) ,
  @ORA_KULLANICI_SUBE varchar(30) ,
  @ORA_KULLANICI_SIRKET varchar(30) ,
  @ORA_KULLANICI_UZMAN varchar(30) ,
  @ORA_KULLANICI_EPOSTA varchar(50) ,
  @ORA_BASVURU_KESIN_KOSUL varchar(1000),
  @ORA_TARIH varchar(30)
  AS
  BEGIN
      SET NOCOUNT ON;
      SET DATEFORMAT DMY;
  BEGIN 
      UPDATE sirket 
      SET bolgeler = '' + CAST(@degerler AS VARCHAR(4000)) + '',
          kullanici = @ORA_KULLANICI_KODU,
          tarih  = @ORA_TARIH
      WHERE kod = @sirketkodu
  END
  </code></pre>
  
  <p>This line of code:</p>
  
  <pre><code>bolgeler ='' + CAST(@degerler AS VARCHAR(4000)) + ''
  </code></pre>
  
  <p>is causing the problem. I tried the following: </p>
  
  <pre><code>bolgeler = @degerler,
  bolgeler = '@degerler',
  bolgeler = '' + @degerler + '',
  bolgeler = CAST(@degerler AS VARCHAR(4000)),
  bolgeler = ''' + @degerler + ''',
  </code></pre>
  
  <p>My <code>@degerler</code> data is a serialized string of php array like this : </p>
  
  <pre><code>string(23) "a:1:{s:2:"gd";s:1:"E";}"
  </code></pre>
  
  <p>and the error is: </p>
  
  <blockquote>
    <p>Conversion failed while converting varchar to int</p>
  </blockquote>
  
  <p>Thanks</p>