搜索产品列表时, @SearchType
参数是可选的。如果 @SearchType
为空或 NULL
那么它应该返回所有产品并且不使用 WHERE
子句。否则,如果它通过了 Equipment
它将使用它来代替。
ALTER PROCEDURE [dbo].[psProducts]
(@SearchType varchar(50))
AS
BEGIN
SET NOCOUNT ON;
SELECT
P.[ProductId],
P.[ProductName],
P.[ProductPrice],
P.[Type]
FROM [Product] P
-- if @Searchtype is not null then use the where clause
WHERE p.[Type] = @SearchType
END
原文由 User970008 发布,翻译遵循 CC BY-SA 4.0 许可协议
只需使用
如果 @searchType 为 null 表示“返回整个表”,则使用
如果@searchType 是一个空字符串,则表示“返回整个表”,然后使用
如果 @searchType 为 null 或空字符串表示“返回整个表”,则使用