title: SQL - I don't see my syntax error
body: <p>I am using SAP Business Objects and updated the software to the newest version <strong>4.2 SP5 Patch 1</strong> and now BO shows me a syntax error, also SQL Syntax Checkers online for this SQL Command:</p>
  
  <pre><code>SELECT
      0 AS "NULL",
      1 AS eins,
      '*' AS stern,
      convert(datetime, '1900-01-01', 102) AS datum
  FROM
      D_MONAT
  WHERE
      D_MONAT.MONAT_ID = 0
  </code></pre>
  
  <p>The database is a Microsoft SQL Server 2014. If I run the command against the database, everything is working fine, but with SAP Business Object, I get a syntax error.</p>
  
  <p>Does anyone see where my syntax error is?</p>
  
  <p>Here is the full SQL Command:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>SELECT DISTINCT
    D_ORGA_VB_REGION_HEUTE.LAND_NAME,
    D_VB_HEUTE.NACHNAME + ', ' + D_VB_HEUTE.VORNAME,
    D_VB_HEUTE.VB_NR,
    D_ORGA_VB_REGION_HEUTE.REGION_NR,
    D_ORGA_VB_REGION_HEUTE.REGION_NAME,
    D_ORGA_VB_HISTORISCH.BEZIRK_NR,
    D_ORGA_VB_HISTORISCH.BEZIRK_NAME,
    D_BERICHTSMONAT.MONAT,
    D_BERICHTSMONAT.MONAT_NAM,
    D_VB_HEUTE.VORNAME + ' ' + D_VB_HEUTE.NACHNAME,
    D_VB_HEUTE.NACHNAME,
    D_ORGA_VB_HEUTE.BEZIRK_NR,
    D_ORGA_VB_HEUTE.VL_NAME,
    sum(VF_AUFTRAG.AE_PROV_PLANKURS)
  FROM
    D_MONAT  D_BERICHTSMONAT INNER JOIN VF_AUFTRAG ON (VF_AUFTRAG.BERMONAT_ID = D_BERICHTSMONAT.MONAT_ID)
     INNER JOIN V_D_VB ON (VF_AUFTRAG.VB_ID=V_D_VB.VB_ID  AND  V_D_VB.EINTRITT_DAT &lt;&gt; V_D_VB.AUSTRITT_DAT)
     INNER JOIN ( 
    select d_orga.*,
    (case
      when (d_orga.LAND_SCHL &lt;&gt; '00' and d_orga.REGION_NR = '00' and d_orga.BEZIRK_NR = '00') then 'LAND'
      when (d_orga.REGION_NR &lt;&gt; '00' and d_orga.BEZIRK_NR = '00') then 'REGION'
      when (d_orga.VL_NR &lt;&gt; '0000000000' and d_orga.BEZIRK_NR = '00') then 'VL'
      when (d_orga.BEZIRK_NR &lt;&gt; '00') then 'BEZIRK'
      else 'UNBEKANNT'
     end) AS knotentyp
  from d_orga
    )  D_ORGA_VB_HISTORISCH ON (substring(V_D_VB.KSLBEZIRK, 1, 6) = D_ORGA_VB_HISTORISCH.BEZIRK_SCHL  AND  D_ORGA_VB_HISTORISCH.GUELTIG_BIS = (SELECT MAX(orga.GUELTIG_BIS) FROM D_ORGA orga WHERE orga.BEZIRK_SCHL = D_ORGA_VB_HISTORISCH.BEZIRK_SCHL))
     INNER JOIN V_D_VB  D_VB_HEUTE ON (V_D_VB.NACHF_VB_NR=D_VB_HEUTE.VB_NR and V_D_VB.NACHF_BUKRS=D_VB_HEUTE.BUKRS  AND  D_VB_HEUTE.GUELTIG_BIS = convert(date,'99991231',112))
     INNER JOIN ( 
    select d_orga.*,
    (case
      when (d_orga.LAND_SCHL &lt;&gt; '00' and d_orga.REGION_NR = '00' and d_orga.BEZIRK_NR = '00') then 'LAND'
      when (d_orga.REGION_NR &lt;&gt; '00' and d_orga.BEZIRK_NR = '00') then 'REGION'
      when (d_orga.VL_NR &lt;&gt; '0000000000' and d_orga.BEZIRK_NR = '00') then 'VL'
      when (d_orga.BEZIRK_NR &lt;&gt; '00') then 'BEZIRK'
      else 'UNBEKANNT'
     end) AS knotentyp
  from d_orga
    )  D_ORGA_VB_HEUTE ON (substring(D_VB_HEUTE.KSLBEZIRK, 1, 2) = D_ORGA_VB_HEUTE.LAND_SCHL and substring(D_VB_HEUTE.KSLBEZIRK, 5, 2) = D_ORGA_VB_HEUTE.BEZIRK_NR and (substring(D_VB_HEUTE.KSLBEZIRK, 3, 2) = D_ORGA_VB_HEUTE.REGION_NR or D_ORGA_VB_HEUTE.BEZIRK_NR &lt;&gt; '00')  AND  D_ORGA_VB_HEUTE.GUELTIG_BIS = convert(date,'99991231',112))
     INNER JOIN ( 
    select d_orga.*,
    (case
      when (d_orga.LAND_SCHL &lt;&gt; '00' and d_orga.REGION_NR = '00' and d_orga.BEZIRK_NR = '00') then 'LAND'
      when (d_orga.REGION_NR &lt;&gt; '00' and d_orga.BEZIRK_NR = '00') then 'REGION'
      when (d_orga.VL_NR &lt;&gt; '0000000000' and d_orga.BEZIRK_NR = '00') then 'VL'
      when (d_orga.BEZIRK_NR &lt;&gt; '00') then 'BEZIRK'
      else 'UNBEKANNT'
     end) AS knotentyp
  from d_orga
    )  D_ORGA_VB_REGION_HEUTE ON (substring(V_D_VB.KSLBEZIRK, 1, 2) = D_ORGA_VB_REGION_HEUTE.LAND_SCHL and substring(V_D_VB.KSLBEZIRK, 5, 2) = D_ORGA_VB_REGION_HEUTE.BEZIRK_NR and (substring(V_D_VB.KSLBEZIRK, 3, 2) = D_ORGA_VB_REGION_HEUTE.REGION_NR or D_ORGA_VB_REGION_HEUTE.BEZIRK_NR &lt;&gt; '00')  AND  D_ORGA_VB_REGION_HEUTE.GUELTIG_BIS = convert(date,'99991231',112))
     INNER JOIN ( 
    select d_orga.*,
    (case
      when (d_orga.LAND_SCHL &lt;&gt; '00' and d_orga.REGION_NR = '00' and d_orga.BEZIRK_NR = '00') then 'LAND'
      when (d_orga.REGION_NR &lt;&gt; '00' and d_orga.BEZIRK_NR = '00') then 'REGION'
      when (d_orga.VL_NR &lt;&gt; '0000000000' and d_orga.BEZIRK_NR = '00') then 'VL'
      when (d_orga.BEZIRK_NR &lt;&gt; '00') then 'BEZIRK'
      else 'UNBEKANNT'
     end) AS knotentyp
  from d_orga
    )  D_ORGA_KNOTEN ON (VF_AUFTRAG.ORGA_ID_MODIFIED=D_ORGA_KNOTEN.ORGA_ID)
     INNER JOIN ( 
    select d_orga.*,
    (case
      when (d_orga.LAND_SCHL &lt;&gt; '00' and d_orga.REGION_NR = '00' and d_orga.BEZIRK_NR = '00') then 'LAND'
      when (d_orga.REGION_NR &lt;&gt; '00' and d_orga.BEZIRK_NR = '00') then 'REGION'
      when (d_orga.VL_NR &lt;&gt; '0000000000' and d_orga.BEZIRK_NR = '00') then 'VL'
      when (d_orga.BEZIRK_NR &lt;&gt; '00') then 'BEZIRK'
      else 'UNBEKANNT'
     end) AS knotentyp
  from d_orga
    )  D_ORGA_KNOTEN_HEUTE ON (D_ORGA_KNOTEN.LAND_SCHL = D_ORGA_KNOTEN_HEUTE.LAND_SCHL and D_ORGA_KNOTEN.BEZIRK_NR = D_ORGA_KNOTEN_HEUTE.BEZIRK_NR and (D_ORGA_KNOTEN.REGION_NR = D_ORGA_KNOTEN_HEUTE.REGION_NR or D_ORGA_KNOTEN_HEUTE.BEZIRK_NR &lt;&gt; '00')  AND  D_ORGA_KNOTEN_HEUTE.GUELTIG_BIS = convert(date,'99991231',112))
  
  WHERE
    (
     ( ('*' IN @Prompt('Land? (* = alle)', 'A', 'VB Orga aktuelle Region\VB Land', multi, free) OR ( D_ORGA_VB_REGION_HEUTE.LAND_NAME ) IN @Prompt('Land? (* = alle)', 'A', 'VB Orga aktuelle Region\VB Land', multi, free))  )
     AND
     ( ('*' IN @Prompt('Region Nr? (* = alle)', 'A', 'VB Orga aktuelle Region\VB Region Nr', multi, free) OR ( D_ORGA_VB_REGION_HEUTE.REGION_NR ) IN @Prompt('Region Nr? (* = alle)', 'A', 'VB Orga aktuelle Region\VB Region Nr', multi, free))  )
     AND
     ( ('*' IN @Prompt('Bezirk Nr? (* = alle)', 'A', 'VB Orga historisch\VB Bezirk Nr', multi, free) OR ( D_ORGA_VB_HISTORISCH.BEZIRK_NR ) IN @Prompt('Bezirk Nr? (* = alle)', 'A', 'VB Orga historisch\VB Bezirk Nr', multi, free))  )
     AND
     (
      D_ORGA_VB_HISTORISCH.BEZIRK_NR  &lt;&gt;  '99'
      OR
      D_ORGA_VB_REGION_HEUTE.LAND_NAME  &lt;&gt;  'Deutschland'
     )
     AND
     ( not (( D_ORGA_VB_REGION_HEUTE.REGION_NR ) = '06' and ( D_ORGA_VB_HISTORISCH.BEZIRK_NR ) = '01')  )
     AND
     ( not (( D_VB_HEUTE.VB_NR ) = 'A0C28')  )
     AND
     (
      (
       ( ( D_BERICHTSMONAT.BEGINN_DAT ) BETWEEN V_D_VB.GUELTIG_VON AND V_D_VB.GUELTIG_BIS
  OR
  ( D_BERICHTSMONAT.ENDE_DAT ) BETWEEN V_D_VB.GUELTIG_VON AND V_D_VB.GUELTIG_BIS  )
       OR
       ( dateadd(year, -1, D_BERICHTSMONAT.BEGINN_DAT) BETWEEN V_D_VB.GUELTIG_VON AND V_D_VB.GUELTIG_BIS
  OR
  dateadd(year, -1, D_BERICHTSMONAT.ENDE_DAT) BETWEEN V_D_VB.GUELTIG_VON AND V_D_VB.GUELTIG_BIS  )
      )
      AND
      (
       (
        ( NOT (( V_D_VB.AUSTRITT_DAT ) IS NOT NULL AND YEAR(( V_D_VB.AUSTRITT_DAT )) &lt;= YEAR(( D_BERICHTSMONAT.BEGINN_DAT )) - 2)  )
        AND
        ( (-1 in @variable('Berichtsjahr?') and ( D_BERICHTSMONAT.JAHR ) in (select distinct MON.JAHR from D_MONAT MON where (dateadd(day,datediff(day,0,current_timestamp),0)-1) between MON.BEGINN_DAT and MON.ENDE_DAT)) or ( D_BERICHTSMONAT.JAHR ) in @Prompt('Berichtsjahr?', 'N', 'Berichtsmonat\Berichtsjahr', multi, free)  )
        AND
        CASE WHEN YEAR(D_VB_HEUTE.AUSTRITT_DAT) &lt;= ( D_BERICHTSMONAT.JAHR )-2 THEN 'ALT' WHEN YEAR(D_VB_HEUTE.AUSTRITT_DAT) = ( D_BERICHTSMONAT.JAHR )-1 THEN 'EX' WHEN YEAR(( D_VB_HEUTE.EINTRITT_DAT )) = ( D_BERICHTSMONAT.JAHR ) AND ( D_VB_HEUTE.EINTRITT_DAT ) &lt;= ( D_BERICHTSMONAT.ENDE_DAT ) THEN 'N' WHEN ( D_VB_HEUTE.EINTRITT_DAT ) &gt; ( D_BERICHTSMONAT.ENDE_DAT ) THEN 'Z' ELSE 'S' END  NOT IN  ( 'ALT'  )
       )
       OR
       convert(varchar, ( D_BERICHTSMONAT.JAHR )) + '_' + ( D_VB_HEUTE.VB_NR )   IN  @dpvalue('A', DP6.DO6a4)
      )
     )
     AND
     ( ('*' IN @Prompt('Verkaufsleiter? (* = alle)', 'A', 'Organisation\Verkaufsleiter', multi, free) OR ( D_ORGA_KNOTEN_HEUTE.VL_NAME ) IN @Prompt('Verkaufsleiter? (* = alle)', 'A', 'Organisation\Verkaufsleiter', multi, free))  )
     AND
     D_VB_HEUTE.VBART_SCHL  &lt;&gt;  'I'
    )
  GROUP BY
    D_ORGA_VB_REGION_HEUTE.LAND_NAME, 
    D_VB_HEUTE.NACHNAME + ', ' + D_VB_HEUTE.VORNAME, 
    D_VB_HEUTE.VB_NR, 
    D_ORGA_VB_REGION_HEUTE.REGION_NR, 
    D_ORGA_VB_REGION_HEUTE.REGION_NAME, 
    D_ORGA_VB_HISTORISCH.BEZIRK_NR, 
    D_ORGA_VB_HISTORISCH.BEZIRK_NAME, 
    D_BERICHTSMONAT.MONAT, 
    D_BERICHTSMONAT.MONAT_NAM, 
    D_VB_HEUTE.VORNAME + ' ' + D_VB_HEUTE.NACHNAME, 
    D_VB_HEUTE.NACHNAME, 
    D_ORGA_VB_HEUTE.BEZIRK_NR, 
    D_ORGA_VB_HEUTE.VL_NAME</code></pre>
  </div>
  </div>
  </p>