There are thee input parameter in my stored procedure. for example,
DECLARE @fromDate DateTime = NULL DECLARE @toDate DateTime = NULL DECLARE @Id int = NULL I want to write a condition in where clause like...if fromDate is provided then searching must be done on @fromDate. if @fromDate is not provided then check for @Id variable if this is not null then search basis on @Id...
Something like...
where CASE when @fromDate is not null THEN (@FromDate is null or ([Created] between @FromDate and @ToDate)) ELSE (@requestId is null or Id=@requestId) there is one problem with below solution...if @fromDate and @Id both are provided then this will do intesect of them and nothing is return.....condition should be like...if @fromDate is given the priority gives to @fromDate even if @Id is provided and result must not be dependend to @Id parameter....
@fromDateand@Idbut then ignore one of them? If I was calling your procedure and passing values for both of them, I certainly wouldn't expect it to do what you describe.