title: CASE statement giving wrong results inside my stored procedure
body: <p>I have a case inside my stored procedure which I use before executing the data.</p>
  
  <pre><code>DECLARE @Setup nvarchar(50)
  
  SELECT 
     @ZipCode = CASE 
                   WHEN REPLACE(@ZipCode, '0', '') = '' 
                     THEN NULL ELSE @ZipCode 
                END,
     @ZipCodeEND = CASE 
                     WHEN REPLACE(@ZipCodeEND, '0', '') = '' 
                       THEN NULL ELSE @ZipCodeEND 
                   END, 
  
  SELECT
      @Setup = CASE WHEN (LEN(ISNULL(@ZipCode, ''))) &gt; 0 THEN '1' ELSE '0' END +
               CASE WHEN (LEN(ISNULL(@ZipCodeEND,''))) &gt; 0 THEN '1' ELSE '0' END
  
  IF ISNULL(@ID, 0) = 0 
  BEGIN
     INSERT INTO dbo.MapToStaticValuesTable(ZipCode, ZipCodeEND, Setup)
     VALUES(@ZipCode, @ZipCodeEND, @Setup)
  END
  </code></pre>
  
  <p>The problem here is even if zipcode and zipcodeEnd are empty and set to null after being saved into the table I keep getting the value "11" instead of getting "00".</p>
  
  <p>Now if I do the same example with <code>nvarchar</code> values it would work, but since <code>ZipCode</code> and <code>ZipCodeEnd</code> are set to <code>int</code> it's acting weird.</p>