-
Notifications
You must be signed in to change notification settings - Fork 0
/
UpdateRacer.sql
43 lines (37 loc) · 1.78 KB
/
UpdateRacer.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
USE [eRaceClub]
GO
/****** Object: StoredProcedure [dbo].[UpdateRacer] Script Date: 12/02/2007 01:26:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[UpdateRacer](@raceID int, @carid int,@oldCarId int )
as
Begin
If @carid <>@oldCarId
Begin
if exists(select carId from RaceDetail where raceId = @raceid and carid = @carid)
--then update the racer
begin
RaisError('Car already exists. Update denied.',16,1)
end
else
begin
--do the update
Update RaceDetail
set CarId = @carid
where CarId = @oldCarid and Raceid = @raceid
end
if @@error<>0 or @@rowcount<>1
RaisError('Could not insert record',16,1)
end
Else
begin
--do the update
Update RaceDetail
set CarId = @carid
where CarId = @oldCarid and Raceid = @raceid
end
if @@error<>0 or @@rowcount<>1
RaisError('Could not insert record',16,1)
end