SELECT CAST(0 AS BIT) AS fchoose , a.fid AS fmaterialID , a.fname AS fmaterialName , a.fsize , a.funit , a.fclassname , b.fsum AS fstoreQty FROM bas_materiel a INNER JOIN inv_materielsave b ON a.fid = b.fmate WHERE b.fsum > 0 AND b.fmonth = ( SELECT MAX(fmonth) FROM inv_materielsave ) AND fclassname = '扁丝' AND ( fid LIKE '%x%' OR fname LIKE '%x%' ) AND a.fsize LIKE '%x%';
/*上面的这种查询会报一个*/
消息 8624,级别 16,状态 21,第 1 行
内部查询处理器错误: 查询处理器无法生成查询计划。有关详细信息,请与客户支持服务部门联系。
修改后:
1 DECLARE @MaxMonth VARCHAR(20); 2 SELECT @MaxMonth = MAX(fmonth) 3 FROM inv_materielsave; 4 SELECT @MaxMonth; 5 SELECT CAST(0 AS BIT) AS fchoose , 6 a.fid AS fmaterialID , 7 a.fname AS fmaterialName , 8 a.fsize , 9 a.funit , 10 a.fclassname , 11 b.fsum AS fstoreQty 12 FROM bas_materiel a 13 INNER JOIN inv_materielsave b ON a.fid = b.fmate 14 WHERE b.fsum > 0 15 AND b.fmonth = ( @MaxMonth ) 16 AND fclassname = '油墨' 17 AND ( a.fid LIKE '%r%' 18 OR fname LIKE '%r%' 19 );
/*这个就是没有问题*/