hey guys,
We have a single Save stored proc for many of our business objects. In this proc, we determine whether its an insert or update. We're converting our SP's from having to pass in a bit saying if its inserting or updating, to doing it a bit smarter. We have two options, both that appear to work the same, but I'm curious as to the best one performane and best-practice wise.
Option 1: Exists
Option 2: Count
Looking forward to your thoughts. Thanks!
D'Arcy
We have a single Save stored proc for many of our business objects. In this proc, we determine whether its an insert or update. We're converting our SP's from having to pass in a bit saying if its inserting or updating, to doing it a bit smarter. We have two options, both that appear to work the same, but I'm curious as to the best one performane and best-practice wise.
Option 1: Exists
Code:
If Exists(Select ComboID1, ComboID2, ComboID3 From Table Where ComboID1 = @ID1 And ComboID2 = @ID2 And ComboID3 = @ID3)
begin
Insert...
end
Else
begin
Update...
end
Option 2: Count
Code:
Delcare @Counter as int
Select @Counter = Count(ComboID1)From Table Where ComboID1 = @ID1 And ComboID2 = @ID2 And ComboID3 = @ID3)
If @Counter = 0
begin
Insert...
end
Else
begin
Update...
end
Looking forward to your thoughts. Thanks!
D'Arcy