Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Which of these is faster? 1

Status
Not open for further replies.

StoneDeCroze

Programmer
Feb 11, 2002
36
0
0
GB
Hi Guys,
Anyone know whis of these will be faster:
@ASWN is a DECIMAL(18,6)
@ID is an INT

IF @ASWN > 0
UPDATE table SET field1=@ASWN WHERE ID=@ID

or

UPDATE table SET field1=@ASWN WHERE ID=@ID AND @ASWN > 0

Logically they are the same:
The first results in the execution of one or two statements, the second only ever one.
However, will the second example always look up ID in table, or if @ASWN <= 0 will it not bother (and is therefore probably quicker).

Thanks for any insights
Peter
 
First case is better, both semantically and performance-wise.

Semantically because code is more readable - and because @ASWN is a constant during query's lifetime.

Performance-wise - because in 2nd example optimizer may apply Filter operator after the rest of WHERE clause. Even if it doesn't do that, 1st case is marginally faster.

------
"There's a man... He's bald and wears a short-sleeved shirt, and somehow he's very important to me. I think his name is Homer."
(Jack O'Neill, Stargate)
[banghead]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top