Anwendungsfall-Anweisung:
SELECT ProductID, ProductName,ProductDesc
FROM product
WHERE ProductID = CASE WHEN @productID IS NULL THEN ProductID ELSE @productID END
Oder IIF()-Funktion, wenn Sie SQL Server 2012 verwenden:
SELECT ProductID, ProductName,ProductDesc
FROM product
WHERE ProductID =IIF(@productID IS NULL, ProductID, @productID )