![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
#3
| |||
| |||
|
|
Hi - I am working on the query below and am trying to incorporate the IF ELSE logic to allow for an update if a record exists already in the tranattendance table and otherwise an insert if it does not. I am new to using IF ELSE. I think I am close but am getting errors related to BEGIN and ELSE. Can someone help? |
#4
| |||
| |||
|
#5
| |||
| |||
|
#6
| |||
| |||
|
|
--update statement if attendance record already exists IF (SELECT * |
#7
| |||
| |||
|
|
Someone may later modify the code and insert something between the UPDATE statement and the @@rowcount check whereupon disaster strikes. |
#8
| |||
| |||
|
|
Someone may later modify the code and insert something between the UPDATE statement and the @@rowcount check whereupon disaster strikes. But just to play devil's advocate, someone could just as easily insert something between the UPDATE statement and the SET/SELECT line. If you think the absence of a blank line will be enough to present disaster, you need to review more code changes. :-) |
#9
| |||
| |||
|
|
Janet (ckauvar (AT) gmail (DOT) com) writes: --update statement if attendance record already exists IF (SELECT * Almost correct. Make that IF EXISTS (SELECT * Rick's solution of using @@rowcount has the advantage of saving you from repeating the conditions in the UPDATE statement in IF EXISTS, so that is a better solution. I would like to change his suggestion one point, though: UPDATE .... SELECT @rowc = @@rowcount IF @rowc = 0 BEGIN INSERT |
![]() |
| Thread Tools | |
| Display Modes | |
| |