CREATE PROCEDURE [dbo].[rpt_Report]
@Product varchar(20) = NULL,
@From DateTime = null,
@To DateTime = null
AS
BEGIN
SELECT
CO.PO, CO.DLVRY,
CASE
WHEN co.CUST_ID = '120' THEN '120'
WHEN HDR.PO_NO LIKE 'CL%' THEN 'CL'
WHEN RED.REU = 'SK' THEN 'STOCK'
WHEN RED.REU = 'SM' THEN 'ORTS'
WHEN co.ITEM = 'PW%' THEN 'CHAIN'
WHEN co.ITEM LIKE 'D%' THEN 'VAN' ELSE 'MISC'
END AS PRODUCT
FROM
co AS co
INNER JOIN
HDR AS HDR ON co.NUMBER = HDR.NUMBER
INNER JOIN
RED AS RED ON co.ITEM = RED.ITEM
WHERE
(co.DLVRY BETWEEN @From AND @To) AND (@Product = PRODUCT)
ORDER BY
co.DLVRY DESC
END
当我执行它时,我收到一条错误消息
消息 207,级别 16,状态 1,过程 rpt_Report,第 34 行
无效的列名称“产品”。
我应该使用 case 字段值作为 where CLAUSE 中的参数。