BETWEEN & PARAMETERS

  • Hi,

    I have a stored procedure, with "nullable" parameters.

    The first line works as expected. I can't get the second line to work.

    Any suggestions?

    Cheers,

    Julian

    --(J.[Week] >= @WeekBegin OR @WeekBegin is null) AND (J.[Week] <= @WeekEnd OR @WeekEnd is null)

    (J.[Week] BETWEEN (@WeekBegin OR @WeekBegin is null) AND (@WeekEnd OR @WeekEnd is null))

  • Could you use something like this?

    J.[Week] BETWEEN ISNULL(@WeekBegin, -1) AND ISNULL(@WeekEnd, 9999999)

    Functions on parameters don't affect SARGability.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Hello Luis,

    Great, that works, thank you.

    Cheers,

    Julian

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply