Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to Return all records in stored procedure if null value passed for a date time field in between fromdate and todate..
Posted

Hi,

Its Simple only.... check Logical Operators (OR, AND) in Google.
I gave Sample Procedure...
SQL
CREATE PROCEDURE test
@StartDate DATETIME=NULL,
@EndDate DATETIME=NULL
AS
BEGIN
	SELECT Column_List
	FROM Table_Name
	WHERE (Date_Field BETWEEN @StartDate AND @EndDate) OR (@StartDate IS NULL AND @EndDate IS NULL)
	-- If Input is having some values or NULL
	-- @StartDate and @EndDate having values or both the Inputs must NULL.	 
END

Regards,
GVPrabu
 
Share this answer
 
Comments
Maciej Los 20-Apr-13 7:06am    
+5
 
Share this answer
 
Comments
gvprabu 21-Apr-13 12:19pm    
yes... correct, we will go for Dynamic query also.
Maciej Los 23-Apr-13 1:34am    
Thank you ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900