Using Not Equals (<>) in SQL Statements

Using Not Equals (<>) in SQL Statements

The following provides information about how to write a query that contains a not equals (<>) operation. The following code example uses <> in the where clause, and the XML parser interprets it as a malformed XML tag.

<ns0:SQLExecute
     xmlns:ns0="http://Microsoft.com/exposed/SQL_SSW/NativeSQL">
<ns0:StatementText>
INSERT INTO TEST (str,num) values ('philip', 3);
<ns0:SQLExecute xmlns:ns0=
     "http://Microsoft.com/exposed/Microsoft/NativeSQL">
     <ns0:StatementText>select * from viewmyreport_auditforecast 
          where column1 <> true;</ns0:StatementText>
     <ns0:ParameterSet> 
<ns0:parameterData> 
</ns0:parameterData> 
     </ns0:ParameterSet> 
</ns0:SQLExecute>

If you use the <> characters in your SQL statement, you get an illegal character error. There are two ways around this error:

  1. Replace the special XML characters < and > with the HTML named entity characters: &lt; and &gt;.

    Certain combinations of characters cause the XML parser to think that it is an XML escape sequence. For example, a > alone does not cause a problem.

  2. Enclose the complete SQL statement with the XML escape CDATA, as in the following code example:

    <ns0:SQLExecute xmlns:ns0=
          "http://Microsoft.com/exposed/Microsoft/NativeSQL">
          <ns0:StatementText>
    <![CDATA[
          select * from viewmyreport_auditforecast where column1 <> true;
          ]]>
    </ns0:StatementText>
    

Community Additions

ADD
Show:
© 2016 Microsoft