Friday, May 10, 2013

Where Am I Doing this wrong? TSQL IF Clause


CREATE PROCEDURE SP_TEST(@SellStartDate datetime = NULL,@SellEndDate datetime = NULL)
AS
BEGIN
IF (@SellEndDate IS NULL AND @SellStartDate IS NOT NULL)
SELECT [ProductID], [Name],[ProductNumber] FROM [AdventureWorks2012].[production].[Product]
WHERE SellStartDate = @SellStartDate
ELSE IF (@SellStartDate IS NULL AND @SellEndDate IS NOT NULL)
SELECT [ProductID], [Name],[ProductNumber]
FROM [AdventureWorks2012].[production].[Product]
WHERE SellEndDate = @SellEndDate
ELSE
IF (@SellStartDate IS NOT NULL AND @SellEndDate IS NOT NULL)
SELECT [ProductID], [Name],[ProductNumber]
FROM [AdventureWorks2012].[production].[Product]
WHERE SellStartDate >= @SellStartDate AND SellEndDate <= @SellEndDate
END

TRY THIS.



Regards, RSingh


No comments:

Post a Comment