';' 附近的语法不正确(微软 SQL 服务器错误 102)

Incorrect Syntax near ';' (Microsoft SQL Server Error 102)

首先,我一直在寻找这个问题的答案,我也是SQL编码的新手,所以请耐心等待。

我正在尝试使用自定义报告在 SCCM 2012r2 中发现客户端计算机的当前运行状况,请参阅下面的代码:

SELECT     v_r_system.name0                                       AS 'Computer Name', 
           v_gs_antimalwarehealthstatus.lastquickscanage          AS 'Days since last quick scan',
           v_gs_antimalwarehealthstatus.lastfullscanage           AS 'Days Since Last Full Scan',
           v_gs_antimalwareinfectionstatus.computerstatus         AS 'Current Status', 
           v_gs_antimalwareinfectionstatus.lastcleaneddectiontime AS 'Last Cleaned' 
FROM       v_gs_antimalwarehealthstatus 
INNER JOIN v_gs_antimalwarehealthstatus 
INNER JOIN v_r_system 
ON         v_gs_antimalwarehealthstatus.resourceid = v_r_system.resourceid 
INNER JOIN v_gs_antimalwareinfectionstatus;

当我在 Report Builder 3.0 中尝试时,我不断收到以下错误:

我好像找不到问题,快把我逼疯了...

无论如何,如果你能为我指明正确的方向,那就太好了。

干杯

您在最后 table v_gs_antimalwareinfectionstatus 加入哪个专栏? 只需在 ON 子句中添加条件,它应该可以正常工作

我认为您的查询有两个问题。第一:

FROM       v_gs_antimalwarehealthstatus 
INNER JOIN v_gs_antimalwarehealthstatus 

为什么内联自身呢?我认为这是不必要的,应该是简单的:

FROM       v_gs_antimalwarehealthstatus 

第二个是最后一个join中缺少ON条件:

INNER JOIN v_gs_antimalwareinfectionstatus ON ... ....;

因此 FROM .. JOIN 部分必须如下所示:

FROM       v_gs_antimalwarehealthstatus 
INNER JOIN v_r_system 
ON         v_gs_antimalwarehealthstatus.resourceid = v_r_system.resourceid 
INNER JOIN v_gs_antimalwareinfectionstatus
ON v_gs_antimalwareinfectionstatus.<column> = <otherTable>.<column>

你只是错过了语句中的 ON Clause,你也可以使用 table alias,因为它使查询看起来很干净。

SELECT     v_r_system.name0                                       AS 'Computer Name', 
           v_gs_antimalwarehealthstatus.lastquickscanage          AS 'Days since last quick scan',
           v_gs_antimalwarehealthstatus.lastfullscanage           AS 'Days Since Last Full Scan',
           v_gs_antimalwareinfectionstatus.computerstatus         AS 'Current Status', 
           v_gs_antimalwareinfectionstatus.lastcleaneddectiontime AS 'Last Cleaned' 
FROM       v_gs_antimalwarehealthstatus AWT
INNER JOIN v_r_system VRS
    ON  AWT.resourceid = VRS.resourceid 
INNER JOIN v_gs_antimalwareinfectionstatus AWI 
    ON [Place the Matching columns here];