1
我不知道我是否可以得到一些帮助,在SQL我有2表基于Person ID他们之间的关系,我想写sp来检查人已经退出: 做一个插入语句,否则做一个更新语句。根据返回值做更新/插入声明
我正在检查是否值IsExit名称表:GSACPeopleBadgeRequest
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[spUpdateIDBadgeInfo]
@PersonID Int,
@RequestedBy Int,
@RequestedOn SmallDatetime,
@BadgeStatusType Int,
@ShippedLocationID Int,
@Notes Varchar(500)= NULL,
@Active bit
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
SET NOCOUNT ON;
DECLARE @retVal INT
SET @retVal = 0
DECLARE @CheckVal Bit
SET @CheckVal = 0
IF @PersonID > 0
BEGIN
'#####################################How do this right.###########################
@CheckVal = select * from GSACPeopleBadgeRequest where PersonID = @PersonID
-- Check if there is any personID in GSACPeopleRequest, if not make a new insert
else
Update dbo.GSACPeopleBadgeRequest
SET
RequestedBy = @RequestedBy,
RequestedOn = @RequestedOn,
BadgeStatusType = @BadgeStatusType,
ShippedLocationID = @ShippedLocationID ,
Notes = ISNULL(@Notes,@Notes),
Active = @Active
WHERE PersonID = @PersonID
-- Set the return value
SET @retVal = CAST(@@ROWCOUNT As int)
Select @retVal
END
END
GO