• Looks to me like all 4 SELECTs are exactly the same, with just a different filter on T_HISTORY.ORIG_DT based on the input parameters.

    Do you really need IF .. THEN blocks with 4 separate branches of execution ?

    Couldn't you just set the local date variables to very low/high values if they are passed as blank, and have 1 SELECT ?

    eg:

    -- Convert blank start date to a date earlier than earliest possible date in

    -- your data

    Select @startDt = Cast(Case when @StartDate = '' Then '01 Jan 1900' Else @startDt End As DateTime)

    Why try to preempt the optimizer with IF statements ? Give it both dates in 1 SELECT, let it optimize based on data distribution and indexes.