Sql server 不等于在sql查询中不起作用

Sql server 不等于在sql查询中不起作用,sql-server,sql-server-2008,Sql Server,Sql Server 2008,嗨,我试着使用下面的查询从表中获取数据,但它不起作用 SELECT ProductMaster.ProductName + '(' + CONVERT(nvarchar(10), 0) + ')' AS orderedproducts, BranchName + '(' + CONVERT(nvarchar(10), SUM(StockInward.Qty)) + ')' AS currentstock, Setup.Id AS BranchId FROM Pro

嗨,我试着使用下面的查询从表中获取数据,但它不起作用

    SELECT
    ProductMaster.ProductName + '(' + CONVERT(nvarchar(10), 0) + ')' AS orderedproducts,
    BranchName + '(' + CONVERT(nvarchar(10), SUM(StockInward.Qty)) + ')' AS currentstock,
    Setup.Id AS BranchId
FROM ProductMaster
INNER JOIN StockOutward
    ON ProductMaster.Productid = StockOutward.productid
INNER JOIN stockinward
    ON ProductMaster.Productid = stockinward.productid
    AND stockinward.StockLocation <> StockOutward.Location
INNER JOIN Setup
    ON stockinward.stocklocation = Setup.id
WHERE StockOutward.ProductId = '7'
GROUP BY    ProductMaster.ProductName,
            StockOutward.Qty,
            BranchName,
            Setup.Id
选择
ProductMaster.ProductName+'('+CONVERT(nvarchar(10),0)+')作为订购产品,
BranchName+'('+转换(nvarchar(10),总和(stockintrown.Qty))+')为当前库存,
Setup.Id为BranchId
来自ProductMaster
内外联
在ProductMaster.Productid=stockoutforward.Productid上
内连接库存
在ProductMaster.Productid=stockinward.Productid上
和stockintrow.StockLocation stockoutrow.Location
内部联接设置
在stockinward.stocklocation=Setup.id上
其中stockoutfort.ProductId='7'
按ProductMaster.ProductName分组,
库存数量,
布兰奇纳姆,
Setup.Id

它将显示表中的所有记录
stockoutforward

Try In your internal join In move In a where子句。
在您的示例中,您是否尝试过更简单的查询(选择1个简单元素并逐个添加innerjoin。

一些示例数据可能会有所帮助!请简化此操作以删除与问题无关的任何联接,或者声明,例如,StockInnown.stocklocation=Setup.id上带有
Setup的内部联接是重现问题所必需的!可以
ProductMaster.Productid
是否为空?如果是,请检查这7是否应该在撇号中?一个
内部连接
子句和
WHERE
子句是相同的,因此没有必要移动条件。是,但是:“stockinward.StockLocation StockOutward.Location”最好将WHERE子句与NOT in指令放在一起。否?如“WHERE stockinward.StockLocati”on not in(选择StockOutside.Location…)进行更多优化