spAddUpdate_ATHLETICS_LOCATIONS
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@ID | int | INOUT | |
@Name | nvarchar(256) | IN | |
@Description | nvarchar(2046) | IN | |
@ContactInfoID | int | IN | |
@IsHome | bit | IN | |
@ClientSitesID | int | IN |
Definition
Copy
CREATE PROCEDURE [dbo].[spAddUpdate_ATHLETICS_LOCATIONS]
(
@ID int output,
@Name nvarchar(256),
@Description nvarchar(2046),
@ContactInfoID int,
@IsHome bit,
@ClientSitesID int
)
AS
SET NOCOUNT ON
IF @ID = 0 BEGIN
-- If the exact athletic location exists, just return the existing location ID.
SELECT @ID = ATHLETICS_LOCATIONS.[ID]
FROM ATHLETICS_LOCATIONS
INNER JOIN ATHLETICS_CONTACTINFO oldContact on ATHLETICS_LOCATIONS.ContactInfoID = oldContact.ID
CROSS JOIN ATHLETICS_CONTACTINFO newContact
WHERE
newContact.ID = @ContactInfoID AND
[Name] = @Name AND
[Description] = @Description AND
[IsHome] = @IsHome AND
[ClientSitesID] = @ClientSitesID AND
oldContact.Address = newContact.Address AND
oldContact.ContactName = newContact.ContactName AND
oldContact.Email = newContact.Email AND
oldContact.Phone = newContact.Phone
IF @ID = 0 BEGIN
INSERT INTO ATHLETICS_LOCATIONS (
[Name],
[Description],
[ContactInfoID],
[IsHome],
[ClientSitesID]
)
VALUES (
@Name,
@Description,
@ContactInfoID,
@IsHome,
@ClientSitesID
)
set @ID = @@Identity;
END
ELSE BEGIN
-- Cleanup [ContactInfoID]
DELETE FROM ATHLETICS_CONTACTINFO WHERE ID = @ContactInfoID;
END
END
ELSE BEGIN
UPDATE ATHLETICS_LOCATIONS SET
[Name] = @Name,
[Description] = @Description,
[ContactInfoID] = @ContactInfoID,
[IsHome] = @IsHome,
[ClientSitesID] = @ClientSitesID
WHERE [ID] = @ID
END