I am trying to write a function which can return true or false or 0 or 1 based on some dates. So let's say you want to check if the start & end date for example "Mar 01 2010" & "Mar 02 2010" lies in the date range or not. so if your date range was "Jan 01 2012 - Dec 30 2012' it will return true otherwise if the date range is 'Jan 01 2011' to Dec 30 2011' then it will return false.
Currently i use the following and i feel it is not optimized and taking some time when you are calling this many times.
CREATE FUNCTION dbo.tmpfnIsDateInRange (@rangeStart DATETIME,
@rangeEnd DATETIME,
@chkStart DATETIME,
@chkEnd DATETIME)
RETURNS TINYINT
AS
BEGIN
RETURN CASE
WHEN @chkStart BETWEEN @rangeStart AND @rangeEnd
OR @chkEnd BETWEEN @rangeStart AND @rangeEnd
THEN
1
WHEN @chkStart <= @rangeStart AND @chkEnd >= @rangeEnd
THEN
1
ELSE
0
END;
END