[英]How to give change working of having function dynamicaly on executing an sql statement?
I'm having a Sql code like as follows 我有一个如下的Sql代码
Select a.ItemCode, a.ItemDesc
From fn_BOM_Material_Master('A', @AsOnDate, @RptDate, @BranchID, @CompID)a
Left Outer Join fn_INV_AsOnDate_Stock(@StockDate, @AsOnDate, @RptDate, @BranchID, @CompID, @Finyear)b
On a.ItemCode=b.ItemCode and b.WarehouseCode<>'WAP'
and a.BranchID=b.BranchID and a.CompID=b.COmpID
Where a.ItemNatureCode = 'F' and a.BranchID = @BranchID and a.CompID = @CompID
Group by a.ItemCode, a.ItemDesc
Having sum(b.CBQty)<=0
Here the problem is that im passing an "@ShowZeroStock" value as as bit if the "@ShowZeroStock" value is '1' then Having should not be validated or (ie: All values from the table should be returned including zero) 这里的问题是,如果“ @ShowZeroStock”值是“ 1”,则我将按位传递“ @ShowZeroStock”值,则该值不应该被验证,或者(即:应返回表中的所有值,包括零)
So How to change the query based on passed bit value "@ShowZeroStock" 那么如何根据传递的位值“ @ShowZeroStock”更改查询
I can Use "If else " condition at the top and remove having in else part, but for a lengthy query i can't do the same. 我可以在顶部使用“ If else”条件,并删除其他部分,但是对于冗长的查询,我无法做到这一点。
这是您想要的逻辑吗?
Having sum(b.CBQty) <= 0 or @ShowZeroStock = 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.