with
a as (SELECT top 1 TCPNO,isnull(SYSTIME,'') SYSTIME FROM view_tbMoltenIronRecord where TCPNO = '1' order by systime desc),
b as (SELECT TOP 1 tcpno, isnull(zkdatetime,'') zkdatetime FROM view_TB_TSGZKRecord where TCPNO = '1' order by zkdatetime desc)
select a.systime,b.zkdatetime from a , b
一条简单的SQL 语句,通过客户端ms sql 直接运行能出结果,完全正常,代码执行后报错 Incorrect syntax near the keyword 'with' ,何解? 而且以前用代码执行也没问题,这个。。,看不懂啊。。。
------解决方案--------------------
with 前面加个;
------解决方案--------------------
;WITH a AS ( SELECT TOP 1
TCPNO ,
ISNULL(SYSTIME, '') SYSTIME
FROM view_tbMoltenIronRecord
WHERE TCPNO = '1'
ORDER BY systime DESC
),
b AS ( SELECT TOP 1
tcpno ,
ISNULL(zkdatetime, '') zkdatetime
FROM view_TB_TSGZKRecord
WHERE TCPNO = '1'
ORDER BY zkdatetime DESC
)
SELECT a.systime ,
b.zkdatetime
FROM a ,
b