寻找零件类别的存储过程

时间:2016-04-08 12:43:19

标签: sql sql-server

我们有一个查找零件类别的存储过程。它们总是从历史上开始,但是我们现在有部分出现在S中,但没有出现在数据中。

我想查找M和S,所以在下面的程序中如何更改它以查找Where Left(CS_REF,1)='M'?

我不是程序员......

ALTER PROCEDURE [dbo].[CatTypes] AS
 SELECT LEFT(CS_REF,3) AS Cat
 FROM a_cstwh
 WHERE LEFT(CS_REF,1) = 'M'
 GROUP BY LEFT(CS_REF,3)
 ORDER BY LEFT(CS_REF,3)
 OPTION (HASH GROUP)

1 个答案:

答案 0 :(得分:0)

试试这个

SELECT LEFT(CS_REF,3) AS Cat
FROM a_cstwh
WHERE LEFT(CS_REF,1) IN ('M', 'S')
GROUP BY LEFT(CS_REF,3)
ORDER BY LEFT(CS_REF,3)
OPTION (HASH GROUP)

(OR)

SELECT LEFT(CS_REF,3) AS Cat
FROM a_cstwh
WHERE LEFT(CS_REF,1) = 'M' OR LEFT(CS_REF,1) =  'S'
GROUP BY LEFT(CS_REF,3)
ORDER BY LEFT(CS_REF,3)
OPTION (HASH GROUP)