以下存储过程是可行的,但我想知道--在SQL Server中处理这种类型的操作是否有最佳实践/模式?本质上,我传入了两个不同的参数。根据传入的“criteria”参数,我运行一个带有一些特定条件的查询语句--谢谢。
ALTER PROCEDURE [dbo].[Select_Project_Info_By_Value]
(
@value VarChar(50),
@criteria VarChar(50)
)
AS
BEGIN
SET NOCOUNT ON;
if @criteria= 'All'
SELECT some some tables...
FROM dbo.Table1
WHERE (NOT (Status = 'ABC'))
else if @criteria = 'X'
SELECT some some tables...
FROM dbo.Table1
WHERE (Matno LIKE '%' + @value + '%') AND (NOT (Status = 'ABC'))
else if @criteria = 'Y'
SELECT some some tables...
FROM dbo.Table1
WHERE (ID LIKE '%' + @value + '%') AND (NOT (Status = 'ABC'))
else if @criteria = 'Z'
SELECT some some tables...
FROM dbo.Table1
WHERE (ProDescr LIKE '%' + @value + '%')
else if @criteria = 'A'
SELECT some some tables...
FROM dbo.Table1
WHERE (CustCode LIKE '%' + @value + '%') AND (NOT (Status = 'ABC'))
else if @criteria = 'B'
SELECT some some tables...
FROM dbo.Table1
WHERE (ApplName LIKE '%' + @value + '%') AND (NOT (Status = 'ABC'))
END