title: The data types nvarchar and nvarchar are incompatible in the subtract operator
body: <p>I know this was asked before. I did research of previous answers and couldn't find solution for my problem. What's most curious in my case is that exact same code works on test database but not on production though they are exactly the same.  Procedure itself is very long but I managed to isolate problematic part. I hope someone sees something I don't because I lost 2 days on this and still have no idea:</p>
  
  <pre><code>DECLARE luUpdateCursor CURSOR  FORWARD_ONLY STATIC READ_ONLY FOR
      SELECT Id, DisplayFormat, LookupName FROM #ProductResults WHERE Value IS NOT NULL AND LEN(LTRIM(RTRIM(LookupName))) &gt; 0
  
  OPEN luUpdateCursor
  
  FETCH NEXT FROM luUpdateCursor
  INTO @Id, @DisplayFormat, @LookUpName
  WHILE @@FETCH_STATUS = 0
  BEGIN
     IF @LocaleID = @SystemLocaleId
          BEGIN
              SET @strSql = '
                  UPDATE PR
                      SET PR.Value = ' + REPLACE(REPLACE(@DisplayFormat,'[','lk.['),',' , '+ '','' + ')  + '          
              FROM
                  #ProductResults PR 
              INNER JOIN
                  tblk_' + RTRIM(@LookUpName) + ' lk WITH(NOLOCK) ON PR.Value = lk.Id 
              WHERE
                  PR.Id = ' + CONVERT(NVARCHAR,@Id)
      END
  ELSE
      BEGIN
          SET @strSql = '
              UPDATE PR
                  SET PR.Value = COALESCE(' + REPLACE(REPLACE(@DisplayFormat,'[','lkl.['),',' , '+ '','' + ') + ',' + REPLACE(REPLACE(@DisplayFormat,'[','lk.['),',' , '+ 
  '','' + ')  + ')            
              FROM
                  #ProductResults PR 
              INNER JOIN
                  tblk_' + RTRIM(@LookUpName) + ' lk WITH(NOLOCK) ON PR.Value = lk.Id 
              LEFT OUTER JOIN
                  tblk_' + RTRIM(@LookUpName) + '_Locale lkl WITH(NOLOCK) ON PR.Value = lkl.fk_Id AND lkl.FK_Locale = ' + CAST(@LocaleID AS NVARCHAR(20)) + ' 
              WHERE
                  PR.Id = ' + CONVERT(NVARCHAR,@Id)
      END 
      EXECUTE sp_executesql @strSql;
      FETCH NEXT FROM luUpdateCursor
      INTO @Id, @DisplayFormat, @LookUpName
  END
  CLOSE luUpdateCursor
  DEALLOCATE luUpdateCursor;
  </code></pre>
  
  <p>Table #ProductREsults has Id INT, and DisplayFormat and LookupNAme are both NVarchar. There is also one very similar query in procedure, actually same but on different table and that one works, so this bothers me so much.
  Sorry if question is stupid.</p>