You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SQL语法错误排查请求:UnmatchedTranCounts附近语法不正确

SQL语法错误排查及修正

运行报错Incorrect syntax near unmatchedTranCounts,问题出在两处语法错误:

错误点分析

  • CTE定义冗余括号:最后一个UNION ALL的子查询结束后多写了一个右括号,导致CTE定义未正确闭合,数据库无法识别后续的CTE引用unmatchedtrancounts。
  • 主查询缺失空格:主查询中tablesloadedtodayfrom未拆分,应改为tablesloadedtoday FROM;uwhere未拆分,应改为u WHERE,缺少空格导致关键字与标识符混淆,数据库解析失败。

修正后的完整SQL代码

WITH unmatchedtrancounts AS
(
       SELECT 'rms.ordhead'            AS tablename,
              Count_big(etl_update_ts) AS todayrows
       FROM   rms.ordhead t1
       WHERE  t1.etl_update_ts >= CONVERT(DATE, Getutcdate())
       UNION ALL
       SELECT 'rms.shipment'           AS tablename,
              Count_big(etl_update_ts) AS todayrows
       FROM   rms.shipment t2
       WHERE  t2.etl_update_ts >= CONVERT(DATE, Getutcdate())
       UNION ALL
       SELECT 'rms.shipsku'            AS tablename,
              Count_big(etl_update_ts) AS todayrows
       FROM   rms.shipsku t3
       WHERE  t3.etl_update_ts >= CONVERT(DATE, Getutcdate())
       UNION ALL
       SELECT 'rms.sups'               AS tablename,
              Count_big(etl_update_ts) AS todayrows
       FROM   rms.sups t4
       WHERE  t4.etl_update_ts >= CONVERT(DATE, Getutcdate())
       UNION ALL
       SELECT 'rms.im_doc_head'        AS tablename,
              Count_big(etl_update_ts) AS todayrows
       FROM   rms.im_doc_head t5
       WHERE  t5.etl_update_ts >= CONVERT(DATE, Getutcdate())
       UNION ALL
       SELECT 'rms.tran_data_history'  AS tablename,
              Count_big(etl_update_ts) AS todayrows
       FROM   rms.tran_data_history t6
       WHERE  t6.etl_update_ts >= CONVERT(DATE, Getutcdate())
       UNION ALL
       SELECT 'rms.im_invoice_detail'  AS tablename,
              Count_big(etl_update_ts) AS todayrows
       FROM   rms.im_invoice_detail t7
       WHERE  t7.etl_update_ts >= CONVERT(DATE, Getutcdate())
       UNION ALL
       SELECT 'rms.tran_data_codes'    AS tablename,
              Count_big(etl_update_ts) AS todayrows
       FROM   rms.tran_data_codes t8
       WHERE  t8.etl_update_ts >= CONVERT(DATE, Getutcdate())
)
SELECT Count(tablename) AS tablesloadedtoday
FROM unmatchedtrancounts u
WHERE u.todayrows > 0

内容的提问来源于stack exchange,提问作者Gyari

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 05:50:25