title: The data types nvarchar and ntext are incompatible in the equal to operator. (402) (SQLExecDirectW)') || SqlAlchemy, Sql Azure
body: <p>DB version : Microsoft SQL Azure (RTM) - 12.0.2000.8 Oct 12 2019 22:46:48 Copyright (C) 2019 Microsoft Corporation</p>
  
  <p>I have a sqlalchemy-orm model <code>Process</code> as given below.</p>
  
  <pre><code>class Process(Base):
      __tablename__ = 'Process'
      id = Column(Integer, primary_key=True, autoincrement=True)
      process = Column(UnicodeText)
      process_length = Column(Integer)
  </code></pre>
  
  <p>I am trying to run the following query to find any row where process matches the string <code>sorted_json</code>.</p>
  
  <pre><code>current_process = session.query(Process).filter(Process.process==sorted_json).one_or_none()
  </code></pre>
  
  <p>This query runs into an error: </p>
  
  <pre><code>ProgrammingError: (pyodbc.ProgrammingError) ('42000', '[42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]The data types nvarchar and ntext are incompatible in the equal to operator. (402) (SQLExecDirectW)')
  </code></pre>
  
  <p>I have tried changing the datatype of the column <code>process</code> to <code>ntext</code> in the backend. When I run the query it gives a bizarre error:</p>
  
  <pre><code>ProgrammingError: (pyodbc.ProgrammingError) ('42000', '[42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]The data types ntext and ntext are incompatible in the equal to operator. (402) (SQLExecDirectW)')
  </code></pre>
  
  <p>It should be noted that <code>sorted_json</code> is a <strong>very long json string</strong> with around 4000 characters. I believe sqlalchemy is casting this string to ntext while querying. </p>
  
  <p>I have instead tried the like function of sqlalchemy like:</p>
  
  <pre><code>current_process = session.query(Process).filter(Process.process.like(sorted_json)).one_or_none()
  </code></pre>
  
  <p>No errors here but it is not providing a match when there is an actual match.</p>
  
  <p>Any help is appreciated!</p>