我正在使用SAP Business Objects并将软件更新到最新版本 4.2 SP5 Patch 1 ,现在BO向我显示语法错误,此SQL SQL命令也在线SQL语法检查器:
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
数据库是Microsoft SQL Server 2014.如果我对数据库运行命令,一切正常,但使用SAP Business Object时,我收到语法错误。
有没有人知道我的语法错误在哪里?
这是完整的SQL命令:
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 <> V_D_VB.AUSTRITT_DAT)
INNER JOIN (
select d_orga.*,
(case
when (d_orga.LAND_SCHL <> '00' and d_orga.REGION_NR = '00' and d_orga.BEZIRK_NR = '00') then 'LAND'
when (d_orga.REGION_NR <> '00' and d_orga.BEZIRK_NR = '00') then 'REGION'
when (d_orga.VL_NR <> '0000000000' and d_orga.BEZIRK_NR = '00') then 'VL'
when (d_orga.BEZIRK_NR <> '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 <> '00' and d_orga.REGION_NR = '00' and d_orga.BEZIRK_NR = '00') then 'LAND'
when (d_orga.REGION_NR <> '00' and d_orga.BEZIRK_NR = '00') then 'REGION'
when (d_orga.VL_NR <> '0000000000' and d_orga.BEZIRK_NR = '00') then 'VL'
when (d_orga.BEZIRK_NR <> '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 <> '00') AND D_ORGA_VB_HEUTE.GUELTIG_BIS = convert(date,'99991231',112))
INNER JOIN (
select d_orga.*,
(case
when (d_orga.LAND_SCHL <> '00' and d_orga.REGION_NR = '00' and d_orga.BEZIRK_NR = '00') then 'LAND'
when (d_orga.REGION_NR <> '00' and d_orga.BEZIRK_NR = '00') then 'REGION'
when (d_orga.VL_NR <> '0000000000' and d_orga.BEZIRK_NR = '00') then 'VL'
when (d_orga.BEZIRK_NR <> '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 <> '00') AND D_ORGA_VB_REGION_HEUTE.GUELTIG_BIS = convert(date,'99991231',112))
INNER JOIN (
select d_orga.*,
(case
when (d_orga.LAND_SCHL <> '00' and d_orga.REGION_NR = '00' and d_orga.BEZIRK_NR = '00') then 'LAND'
when (d_orga.REGION_NR <> '00' and d_orga.BEZIRK_NR = '00') then 'REGION'
when (d_orga.VL_NR <> '0000000000' and d_orga.BEZIRK_NR = '00') then 'VL'
when (d_orga.BEZIRK_NR <> '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 <> '00' and d_orga.REGION_NR = '00' and d_orga.BEZIRK_NR = '00') then 'LAND'
when (d_orga.REGION_NR <> '00' and d_orga.BEZIRK_NR = '00') then 'REGION'
when (d_orga.VL_NR <> '0000000000' and d_orga.BEZIRK_NR = '00') then 'VL'
when (d_orga.BEZIRK_NR <> '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 <> '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 <> '99'
OR
D_ORGA_VB_REGION_HEUTE.LAND_NAME <> '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 )) <= 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) <= ( 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 ) <= ( D_BERICHTSMONAT.ENDE_DAT ) THEN 'N' WHEN ( D_VB_HEUTE.EINTRITT_DAT ) > ( 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 <> '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
答案 0 :(得分:0)
您没有语法错误。您的语法完全有效。
最初,我虽然可能与SET QUOTED_IDENTIFIER
有关,所以我决定测试一下:
SET QUOTED_IDENTIFIER ON;
CREATE TABLE D_MONAT
(
MONAT_ID int
);
INSERT INTO D_MONAT(MONAT_ID) VALUES (0), (0);
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;
SET QUOTED_IDENTIFIER OFF;
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;
Both queries executed without an error,所以还有其他事情可能会发生。
尝试将"NULL"
更改为'NULL'
或[NULL]
,看看是否有所不同。