Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2003

    Unanswered: variable comparison vs. field comparison

    I have this bit of code throughout that page using in case statements:
    when pa.ssn = pa1.ssn and
    (pa.firstname = pa1.firstname)
    then 5

    This field comparison is used 100's of times through a laddered CASE statement.

    Which is faster, leaving it like above so a field comparison is performed over and over, or doing the following:

    Select @temp1 = case when pa.firstname = pa1.firstname then 1 else 0 end

    and then checking like this throughout the page:
    when pa.ssn = pa1.ssn and
    then 5

    Thanks for any help you can provide.

  2. #2
    Join Date
    Dec 2002
    Czech Republic
    Preevaluation of conditions in one sql command can be used only in setting select or update. Evaluating of conditions is much faster than modifiing data. Post more information about situation you want to optimize.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts