I have a date and if this date between two dates then need to return 1 otherwise it returns 0.this is a function.
CREATE FUNCTION [dbo].[funcDateBet]
(
@procDate datetime,
)
RETURNS DateTime
AS
BEGIN
DECLARE @DateIn DateTime = '2022-01-01 00:00:00.000';
DECLARE @DateOut DateTime = '2022-08-20 00:00:00.000';
DECLARE @returnval DateTIME;
DECLARE @InsidePeriod INT;
//In here need to check procDate is inside DateIn & DateOut.. If Inside it then @InsidePeriod should be 1 else 0
IF(@InsidePeriod = 1)
//Some Query Here
ELSE
//Some Query Here
RETURN @returnval
END
GO
CodePudding user response:
You can simply do this :
CREATE FUNCTION [dbo].[funcDateBet]
(
@procDate DATETIME
)
RETURNS DATETIME
AS
BEGIN
RETURN CASE WHEN @procDate BETWEEN '2022-01-01 00:00:00.000' AND '2022-08-20 00:00:00.000' THEN 1 ELSE 0 END
END