解决方案:通过临时表先将数据查出再运用规则。
原规则:
SELECT '@IsAfterPA_01',CASE WHEN COUNT(*)>0 THEN 'TRUE' ELSE 'FALSE' END FROM 表A p1,表A p2 WHERE p1.id = @flow_id AND p2.pdctno = @pdctno AND p2.techno = 'PA_01' AND p2.globalOrder < p1.globalOrder;
改后规则:
SELECT * INTO #temp_表 FROM 表A WHERE pdctno = @pdctno;
SELECT '@IsAfterPA_01',CASE WHEN COUNT(*)>0 THEN 'TRUE' ELSE 'FALSE' END FROM #temp_表 p1,#temp_表 p2 WHERE p1.id = @flow_id AND p2.pdctno = @pdctno AND p2.techno = 'PA_01' AND p2.globalOrder < p1.globalOrder;
DROP TABLE #temp_表;