Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to create stored procedure for fetching all dates between two dates, if given two dates are different.

If that two dates are same, then I want to access all it's events in express database in ASP.NET
Posted
Updated 25-Jan-11 1:54am
v2

Also you can do something like

create PROCEDURE testdate @date1 datetime, @date2 datetime
AS
if(@date1!=@date2)begin
SELECT datecreated FROM tablename WHERE datecreated BETWEEN @date1 AND @date2
end
else
begin
select * from tablename
end
 
Share this answer
 
SQL
select * 
from table
where table.DateColumn >= @StartDate AND table.DateColumn <= @EndDate
 
Share this answer
 
You need to be extra careful while using comparison operators for comparing date types.

http://www.texastoo.com/post/2010/09/04/Comparison-operators-in-TSQL-for-Dates-3c-3e-3c3d-3e3d-BETWEEN.aspx[^]

You can also give a try to DateDiff in case it fits in your scenario.
http://msdn.microsoft.com/en-us/library/ms189794.aspx[^]
 
Share this answer
 

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