CREATE PROCEDURE dbo.sample @start DATE,@end DATE,@type VARCHAR(5)
AS
SELECT o.O_Id,
o.Sale_Price,
o.Private_Band,
c.Date_of_Purchase,
c.Date_Redeemed,
c.Type,
c.Points_Issued,
o.Date_of_Purchase
FROM Order_Details o,
Transaction_Historys c
WHERE CASE
WHEN o.Date_of_Purchase BETWEEN @start AND @end
AND (c.Type = @type) THEN 1
WHEN c.Type = @type THEN 1
ELSE 0
END = 1
GO
EXECUTE dbo.sample @type=NULL,@start='2012-03-01',@end='2012-03-30'
GO
Когда я тестирую с @type=null
, я не получаю данных. Мне нужно обработать менее двух случаев, когда условие
INput CASE1=wen @type is NULL-> WHERE c.Date_Redeemed BETWEEN @Start AND @End-- this should execute
If CASE2=wen @start,@end is NULL->WHERE c.Type=@type-- this should execute