I have a procedure I am trying to create, but I am unable to get the DateTime field to behave the way I want.
I'd like to be able to call my procedure and either include start date and end date or just start date and nothing or start date and a space:
EXECUTE sp_myProcedure '01/17/2005', '05/01/2006'
or
EXECUTE sp_myProcedure '01/17/2005'
or
EXECUTE sp_myProcedure '01/17/2005', ' '
What I have written does not work because SQL Server 2000 will not let me compare a DateTime to ' '.
What I would like to do is ask if the end date is valid, but I do not know how to post that question.
Could someone tell me how to ask SQL Server 2000 if my end date is a valid DateTime field?
CREATE PROCEDURE sp_myProcedure(@DateStart DateTime, @DateEnd DateTime) AS
SELECT [Operator], [Serial_Number], [Date_Time], [System]
FROM Company_Parts
WHERE
CASE WHEN (@DateEnd IS '') THEN (@DateStart <= Date_Time)
ELSE (Date_Time BETWEEN @DateStart AND @DateEnd)
END