以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]SQL语句问题,求帮助~  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=44153)

--  作者:jiskin
--  发布时间:2013/12/24 12:47:00
--  [求助]SQL语句问题,求帮助~
where 语句后面可以用 + - 吗?

大致如下结构:Select * from {Material_List} where StockQty + (子查询) + (子查询) + (子查询) - (子查询) <= QuantityAlert and (MaterialsClass = \'外购件\' or MaterialsClass = \'标准件\')

请问这样写是不是不正确?加上子查询就没结果了……研究半天了,还发现个问题,最后的or 一定要括弧括起来才生效居然!

实际查询语句如下:
Select * from {Material_List} where StockQty + (select sum(Quantity) from{Buy_List} where Material = {Material_List}.MaterialSpecification and Status <> \'已请购\') + (select sum(Quantity) from{Request_Orders} where Material = {Material_List}.MaterialSpecification and Status = \'已请购\') + (Select sum(Quantity) from {Purchase_Orders} where Material = {Material_List}.MaterialSpecification And IQCNumber In (Select IQCNumber from {IQC_List} where Status <> \'已入库\'or Status is NULL)) - (Select sum(Failure) from {Purchase_Orders} where Material = {Material_List}.MaterialSpecification And IQCNumber In (Select IQCNumber from {IQC_List} where Status <> \'已入库\'or Status is NULL)) <= QuantityAlert and (MaterialsClass = \'外购件\' or MaterialsClass = \'标准件\')


--  作者:狐狸爸爸
--  发布时间:2013/12/24 13:07:00
--  

看不懂你的问题,这个你最好学一下sql的语句,找本书看看吧。

 


--  作者:jspta
--  发布时间:2013/12/24 14:31:00
--  
(StockQty + (子查询) + (子查询) + (子查询) - (子查询)) <= QuantityAlert

这个可能要加括号,否则解析出现错误了
[此贴子已经被作者于2013-12-24 14:31:57编辑过]

--  作者:jiskin
--  发布时间:2013/12/24 15:10:00
--  
以下是引用jspta在2013-12-24 14:31:00的发言:
(StockQty + (子查询) + (子查询) + (子查询) - (子查询)) <= QuantityAlert

这个可能要加括号,否则解析出现错误了
[此贴子已经被作者于2013-12-24 14:31:57编辑过]

 

刚自己研究出来了 不是因为括号的问题 是需要加上 isnull 图片点击可在新窗口打开查看 弄了大半天 郁闷