Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2006

    Question Unanswered: Simple SQL Question regarding Update Query

    Can we add if statements in Update query?

    I have to do following task in one stored proc:
    I am passing 2 param to the stored proc @spkid, @Repspk

    Update myTable
    set spk1=@Repspk
    where spk1=@spkid

    Update myTable
    set spk2=@Repspk
    where spk2=@spkid

    Update myTable
    set spk3=@Repspk
    where spk3=@spkid

    Instead of writing 3 update statements what is the other option that will make the query run faster? Thanks alot for transfering knowledge...

  2. #2
    Join Date
    Jun 2003
    Provided Answers: 1
    You CAN do this in a single statement, but all the possible "solutions" I can think of would have their own performance drawbacks. There is no guarantee that any of them would be faster.
    If you have indexes on spk1, spk2, and spk3, you should get about the best performance possible from your existing script.
    If it's not practically useful, then it's practically useless.

    blindman "sqlblindman"

Posting Permissions

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