试图添加一个额外的产品组" +"

时间:2014-03-31 09:50:23

标签: sql

只是从前雇员那里获得工作并且我对SQL很陌生,我似乎很快就把它拿起来但是因为我们的大多数系统都是现场的,所以我对在网站上做出任何重大改变犹豫不决基于这些系统的完全垮掉。

我的问题是,目前有以下代码:

SELECT  *
FROM
(
SELECT  p.product,
        p.description,
        p.warehouse,
        CASE
            WHEN RIGHT(RTRIM(p.product),2) = '+P' THEN (SELECT physical_qty - allocated_qty FROM scheme.stockm p2 WHERE p2.warehouse = p.warehouse AND p2.product = REPLACE(p.product, '+P', ''))
            WHEN RIGHT(RTRIM(p.product),2) = '+P1' THEN (SELECT physical_qty - allocated_qty FROM scheme.stockm p2 WHERE p2.warehouse = p.warehouse AND p2.product = REPLACE(p.product, '+P1', ''))
            ELSE physical_qty - allocated_qty
        END AS 'Stock',
        CASE
            WHEN warehouse = 'X1' THEN trade.price * 0.85
            ELSE trade.price * 0.8
        END AS 'Price'
FROM    scheme.stockm p INNER JOIN
        scheme.oplistm AS trade WITH(NOLOCK) ON p.product = trade.product_code AND trade.price_list = 'MT'
WHERE   (warehouse = 'X1'
OR      warehouse = 'X2')
AND     analysis_b <> '0421'
AND     analysis_b <> '0531'
AND     analysis_b <> '0409'
) AS t
WHERE t.Stock > 0
AND RTRIM(product) + '+P' NOT IN
(SELECT product
FROM    scheme.stockm
WHERE   warehouse = 'X1'
OR      warehouse = 'X2')
AND RTRIM(product) + '+P1' NOT IN
(SELECT product
FROM    scheme.stockm
WHERE   warehouse = 'X1'
OR      warehouse = 'X2')
AND     product NOT LIKE 'BAG%'
AND     product NOT LIKE 'MDS%'
AND     UPPER(description) NOT LIKE '%STAND%'

此代码目前列出了所有产品的价目表,但标题中包含+ p的产品系列除外?我正在询问当前代码需要做什么才能将产品范围包含在+ p中?因为这需要包括在内。

非常感谢任何帮助。

亲切的问候 Dean Gent

0 个答案:

没有答案