locked
how can I give < or <= condition in my sql under xml tag RRS feed

  • Question

  • User-1355965324 posted

    I am trying to give sql under the tag  <SQL> but here <  and <= is not working . How can I give < or <= sign in my sql ,  how can give  sql    <. or <= in where condition  Please can you help  ?

    <Content>
    <SQL ID="BSSQL">
      select code, name  from Employee
      where birthdate >=  DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE())-1, 0)
      And birthdate < DATEADD(month, DATEDIFF(month, 0, GETDATE()), 0)
     And birthYear<> 2002
    </SQL>

    With Many Thanks

    Pol

    Thursday, December 3, 2020 6:55 PM

Answers

  • User475983607 posted

    Use standard XML encoding to encode the special XML characters.

      <SQL ID="BSSQL">
        select code, name  from Employee
        where birthdate &gt;=  DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE())-1, 0)
        And birthdate &lt; DATEADD(month, DATEDIFF(month, 0, GETDATE()), 0)
        And birthYear&lt;&gt; 2002
      </SQL>

    Google for learning encoding.  

    https://www.google.com/search?q=xml+encode+c%23

    The C# XML namespace docs also covers the fundamentals.

    https://docs.microsoft.com/en-us/dotnet/api/system.xml?view=net-5.0

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 3, 2020 7:05 PM
  • User303363814 posted

    You want the XML parser to ignore, but include, your literal SQL statement.. To do this, XML can have a CDATA section.  This is blocks of text that are not parsed by the XML parser.

    <SQL ID="BSSQL">
     <![CDATA[
      select code, name  from Employee
      where birthdate >=  DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE())-1, 0)
      And birthdate < DATEADD(month, DATEDIFF(month, 0, GETDATE()), 0)
     And birthYear<> 2002
    ]] >
    </SQL>

    There is now no need to encode any special characters, making the xml easier to read (and copy/paste from)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 3, 2020 10:45 PM

All replies

  • User475983607 posted

    Use standard XML encoding to encode the special XML characters.

      <SQL ID="BSSQL">
        select code, name  from Employee
        where birthdate &gt;=  DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE())-1, 0)
        And birthdate &lt; DATEADD(month, DATEDIFF(month, 0, GETDATE()), 0)
        And birthYear&lt;&gt; 2002
      </SQL>

    Google for learning encoding.  

    https://www.google.com/search?q=xml+encode+c%23

    The C# XML namespace docs also covers the fundamentals.

    https://docs.microsoft.com/en-us/dotnet/api/system.xml?view=net-5.0

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 3, 2020 7:05 PM
  • User753101303 posted

    Hi,

    And if not done already prefer to use an XML API that will encode this for you rather than building directly yourself a text file.

    Thursday, December 3, 2020 8:49 PM
  • User303363814 posted

    You want the XML parser to ignore, but include, your literal SQL statement.. To do this, XML can have a CDATA section.  This is blocks of text that are not parsed by the XML parser.

    <SQL ID="BSSQL">
     <![CDATA[
      select code, name  from Employee
      where birthdate >=  DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE())-1, 0)
      And birthdate < DATEADD(month, DATEDIFF(month, 0, GETDATE()), 0)
     And birthYear<> 2002
    ]] >
    </SQL>

    There is now no need to encode any special characters, making the xml easier to read (and copy/paste from)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 3, 2020 10:45 PM