Simple use of IF inside procedure I'm creating a simple query, a simple select like select x,y,z from etc etc but in the software, there are start date and end date.

If the user fills in only the first date, then it will use a where clause like this:

where....
and...
and x.date &gt;= Startdate


If the user fills in both dates, it will use:

where....
    and...
    and x.date between @Startdate and @enddate


If the user fills in only end date:

 where....
    and...
    and x.date &lt; @enddate


I'm getting a syntax error with everything I'm trying to do.

 where....
        and...
        case when @startdate is not null and @enddate is null
           and x.date &gt;= Startdate


Or even using if. What is the correct syntax for this? Or this is something programmers need to fix inside the software's code?
Try like this

WHERE....
AND...
AND (x.DATE&gt;= @Startdate OR @Startdate IS NULL)
AND (x.DATE&lt;= @enddate OR @enddate IS NULL)


Possibly with OPTION (RECOMPILE).

See Dynamic Search Conditions in T‑SQL by Erland Sommarskog.